Đây là cách hiển thị vùng vận chuyển và giá cước trên trang Single Product Page, người dùng biết họ sẽ phải chi bao nhiêu khi đến Giỏ hàng/Thanh toán và không có phí “ẩn”. với cách hiển thị này sẽ giúp tỷ lệ chuyển đổi doanh số tốt hơn!

Trong hướng dẫn này, chúng ta sẽ xem cách lấy dữ liệu từ  “WooCommerce Shipping Zones Data”

Thêm PHP tùy chỉnh trong functions.php

add_action( 'woocommerce_after_add_to_cart_form', 'trendy_shipping_rates_single_product' );
 
function trendy_shipping_rates_single_product() {
   global $product;
   if ( ! $product->needs_shipping() ) return;
   $zones = WC_Shipping_Zones::get_zones();
   echo '<div><i class="fas fa-truck"></i> ' . __( 'Shipping', 'woocommerce' );
   echo '<table>';
   foreach ( $zones as $zone_id => $zone ) {
      echo '<tr><td>';
      echo $zone['zone_name'] . '</td><td>';
      $zone_shipping_methods = $zone['shipping_methods'];
      foreach ( $zone_shipping_methods as $index => $method ) {
         $instance = $method->instance_settings;
         $cost = $instance['cost'] ? $instance['cost'] : $instance['min_amount'];
         echo $instance['title'] . ' ' . wc_price( $cost ) . '<br>';
      }
      echo '</td></tr>';
   }
   echo '</table></div>';
}

 

Thử thôi nào!