Home » WooCommerce: Show Shipping Rates @ Single Product Page

WooCommerce: Show Shipping Rates @ Single Product Page

by Tutor Aspire

In today’s “Watch me customize my WooCommerce marketplace website” episode (see previous customization re: external products) we’ll go printing shipping zones and rates on the single product page, so that users know how much they’ll end up spending once they reach the Cart/Checkout and there are no “hidden” fees. Not bad for some transparency = better sales conversion rate!

You can see the result on my own website, at this link for example: https://www.apieceofsicily.com/en/shop/sicilian-crafts/ciabattino/ – as you can see right below the “Add to Cart” button there is a shipping table with the data taken from the shipping zones.

I must say I use YITH WooCommerce Multi Vendor / Marketplace so that data is actually taken from each vendor’s shipping setup – so in this tutorial we will first see how to get the default “WooCommerce Shipping Zones Data” and in a second snippet we will instead see how to get the info for each vendor instead.

Either way, enjoy!

Here’s the new “Shipping” section on the WooCommerce Single Product Page that gathers data from each shipping zones.

PHP Snippet: Display Shipping Zones & Methods @ WooCommerce Single Product Page (WooCommerce Plugin)

/**
 * @snippet       Show Shipping Rates - WooCommerce Single Product
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WooCommerce 6
 * @donate $9     https://www.tutoraspire.com
 */

add_action( 'woocommerce_after_add_to_cart_form', 'tutoraspire_shipping_rates_single_product' );

function tutoraspire_shipping_rates_single_product() {
   global $product;
   if ( ! $product->needs_shipping() ) return;
$zones = WC_Shipping_Zones::get_zones();
echo '
' . __( 'Shipping', 'woocommerce' ); echo ''; foreach ( $zones as $zone_id => $zone ) { echo ''; } echo '
'; echo $zone['zone_name'] . ''; $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 ) . '
'; } echo '
'; }

PHP Snippet: Display Vendor’s Shipping Zones & Methods @ WooCommerce Single Product Page (YITH WooCommerce Multi Vendor / Marketplace Plugin)

/**
 * @snippet       Show YITH Vendor Shipping Rates - WooCommerce Single Product
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WooCommerce 6
 * @donate $9     https://www.tutoraspire.com
 */

add_action( 'woocommerce_after_add_to_cart_form', 'tutoraspire_yith_vendor_shipping' );

function tutoraspire_yith_vendor_shipping() {
global $product;
   if ( ! $product->needs_shipping() ) return;
$product_id = $product->get_id();
$vendor = yith_get_vendor( $product, 'product' );
if ( $vendor->zone_data ) {
echo '
' . __( 'Shipping', 'woocommerce' ); echo ''; foreach ( $vendor->zone_data as $key => $zone ) { echo ''; } echo '
'; echo $zone['zone_name'] . ''; $zone_shipping_methods = $zone['zone_shipping_methods']; foreach ( $zone_shipping_methods as $index => $method ) { $cost = $method['method_cost'] ? $method['method_cost'] : $method['min_amount']; echo $method['method_title'] . ' ' . wc_price( $cost ) . '
'; } echo '
'; } }

You may also like