Here’s a way to print 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!
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!
PHP Snippet: Display Shipping Zones & Methods @ WooCommerce Single Product Page (WooCommerce Plugin)
/**
* @snippet Show Shipping Rates - WooCommerce Single Product
* @how-to businessbloomer.com/woocommerce-customization
* @author Rodolfo Melogli, Business Bloomer
* @compatible WooCommerce 8
* @community https://businessbloomer.com/club/
*/
add_action( 'woocommerce_after_add_to_cart_form', 'bbloomer_shipping_rates_single_product' );
function bbloomer_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>';
}
Advanced Plugin: WooCommerce Shipping Calculator
The above code snippet displays all the shipping zones and options on the product page. As an alternative, I also found a plugin that lets you add the full WooCommerce shipping calculator to the product page.
WooCommerce Shipping Calculator lets customers enter their location and then displays the available shipping options. Itβs a simple and flexible plugin and comes with a choice of options for where to display the calculator on the product page.
Hi!
Love your blog! I have been using several of your snippets on my projects.
This snippet is awesome, but how can I get this to work if I have multiple shipping classes?
Kind Regards,
Andree
Hello Andree, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Please tell me how to hide it on digital products? I’ve both physical and digital products. It is also visible on digital products.
You’re 100% right! Check the new version please
Rodolfo, thanks for the snippet.
I’m using “WooCommerce Table Rate Shipping” from Bolder Elements.
You code is printing shipping zones, title but all rates are being displayed as 0,00.
Any chance to get the correct rates with your code?
Hi Vinicius, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
This is exactly what I was looking for. So excited to find your site and this snippet.
I tried the first code and it does show Shipping and the table below. However it shows shipping only for in-country shipping (I have two zones set up – in-country and international). And it shows 0 in the cost field even though I have defined costs for the shipping class selected for the product. Could this be because I have Dokan marketplace? Any pointers to what I might check for to get this to work?
Using your YITH code (replacing it with dokan) didn’t work at all as I guess Dokan probably has different variables.
Thanks Manish, yes, I believe the code may need to be customized to make it compatible with Dokan
Hello and thank you for this.
I have an issue though. When I add the code to functions.php I get the following error.
Notice: Undefined index: min_amount in /var/www/webroot/stage-sneakfreakscy/wp-content/themes/shoptimizer-child-theme/functions.php on line 275
Home Delivery β¬0,00
Why is that please?
Usually free shipping rates have a “min_amount” that trigger the method. If you don’t have this, the code won’t find it, and you have this “Notice” (which is nothing serious).
If you want to fix this, you could change
to
Hi Rodolfo, and thanks again for all your great help.
I tried it, and got the error
Warning: Undefined array key “min_amount” even after changing the min -amount line
Any idea ? Thanks again !
You shouldn’t worry about warning too much – anyway, you probably need to check if the array key is set:
Hi Rodolfo,
I placed the php snippet at the bottom of my child themes functions.php file.
But there’s nothing showing up at my product pages π
P.s. it’s not the website which I put in my info but another website I’m working on.
You don’t even see the “Shipping” title? If yes, then it’s because you’re on a custom theme and default WooCommerce hooks won’t work out of the box. Let me know
Hey Rodolfo,
I ran into this issue as well. I just did a quick copy/paste and nothing showed up. Double checked the code for the “PHP Snippet: Display Shipping Zones & Methods @ WooCommerce Single Product Page (WooCommerce Plugin)” version and there’s no “add_action” included.
Once I added that your snippet worked just fine. It might be helpful to update the snippet to include that so that people don’t get confused as to why it’s not working. π
Sorry about that. Fixed
Hi Rodolfo
long time subscriber first time commenting.
is there any chance you could adapt this snippet so that it works with another marketplace plugin called WC vendors.
I tried swapping yith_get_vendor for WCV_Vendors::is_vendor and WCV_Vendors::get_vendor_id but just gets a critical error. obviously, my cutting and pasting technique is being exposed here π
thanks in advance
mark
Hey Mark, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
It shows for flat rate: β¬ 0,00 instead of the right rate of β¬ 8,00
Not sure, works on my site. Can you try disable all plugins but Woo and test again?
Hi Rodolfo!
Love your blog, has helped me tremendously over the years.
I work with geolocation for an even better conversion – customers in Italy have no need to see shipping rates/eta for Sweden for example. It will only confuse them.
Tip: by adding a custom ETA field to the shipping methods you can specify the ETA per shipping method/zone. Any idea how we can present this custom field on the product page as well?
Hey Wolf, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Nice feature but it also shows “Free Shipping EURO 200” where it should rather say Free shipping above EURO 200 spend.
Yep, you can totally add that (untested):