Woocommerce CMS code for shipping price on product page

Seagull
111 Posts
Seagull posted this 29 January 2017

Hello, I was just trying to see if there was a way to have the shipping cost of an item displaying on the product's page? I think it should be doable with the CMS code but unfortunately I am not proficient enough in coding to work out what it is that I need.

: I found this discussion on Stackoverflow

the answer there was to add this code to the template:

$shipping_class_id = $product->get_shipping_class_id();
$shipping_class= $product->get_shipping_class();
$fee = 0;


if ($shipping_class_id) {
   $flat_rates = get_option("woocommerce_flat_rates");
   $fee = $flat_rates[$shipping_class]['cost'];
}


$flat_rate_settings = get_option("woocommerce_flat_rate_settings");
echo 'Shipping cost: ' . ($flat_rate_settings['cost_per_order'] + $fee);

But I'm not sure how or what I need to pull out of that to add to the CMS code as in these examples here: http://answers.themler.com/articles/67129/tips-and-tricks

I don't know if it makes a difference but this website I am working on uses all flat rates for shipping with different values according to the size/weight either.

Best regards,
Angela

Hello, I was just trying to see if there was a way to have the shipping cost of an item displaying on the product's page? I think it should be doable with the CMS code but unfortunately I am not proficient enough in coding to work out what it is that I need. : [I found this discussion on Stackoverflow][1] the answer there was to add this code to the template: $shipping_class_id = $product->get_shipping_class_id(); $shipping_class= $product->get_shipping_class(); $fee = 0; if ($shipping_class_id) { $flat_rates = get_option("woocommerce_flat_rates"); $fee = $flat_rates[$shipping_class]['cost']; } $flat_rate_settings = get_option("woocommerce_flat_rate_settings"); echo 'Shipping cost: ' . ($flat_rate_settings['cost_per_order'] + $fee); But I'm not sure how or what I need to pull out of that to add to the CMS code as in these examples here: [http://answers.themler.com/articles/67129/tips-and-tricks][2] [1]: http://stackoverflow.com/questions/40279590/woocommerce-get-shipping-costs-on-the-product-page [2]: http://answers.themler.com/articles/67129/tips-and-tricks I don't know if it makes a difference but this website I am working on uses all flat rates for shipping with different values according to the size/weight either. Best regards, Angela
Vote to pay developers attention to this features or issue.
6 Comments
Order By: Standard | Newest
Support Team
Support Team posted this 30 January 2017

Hi,

For the provided code you just need to wrap in in PHP tags and add to the CMS Code control:

<?php
$shipping_class_id = $product->get_shipping_class_id();
$shipping_class= $product->get_shipping_class();
$fee = 0;

if ($shipping_class_id) {
$flat_rates = get_option("woocommerce_flat_rates");
$fee = $flat_rates[$shipping_class]['cost'];
}

$flat_rate_settings = get_option("woocommerce_flat_rate_settings");
echo 'Shipping cost: ' . ($flat_rate_settings['cost_per_order'] + $fee);
?>

It works for my sample product which has one Shipping Class assigned. I'm not sure what will happen if you're using different classes for different product attributes. This question is not related to Themler itself. This is Woocommerce functionality.

Thank you,
Olivia

Hi, For the provided code you just need to wrap in in PHP tags and add to the CMS Code control: `<?php $shipping_class_id = $product->get_shipping_class_id(); $shipping_class= $product->get_shipping_class(); $fee = 0;` `if ($shipping_class_id) { $flat_rates = get_option("woocommerce_flat_rates"); $fee = $flat_rates[$shipping_class]['cost']; }` `$flat_rate_settings = get_option("woocommerce_flat_rate_settings"); echo 'Shipping cost: ' . ($flat_rate_settings['cost_per_order'] + $fee); ?>` It works for my sample product which has one Shipping Class assigned. I'm not sure what will happen if you're using different classes for different product attributes. This question is not related to Themler itself. This is Woocommerce functionality. Thank you, Olivia
Seagull
111 Posts
Seagull posted this 30 January 2017

Thank you Olivia, I'll try that today.

Best regards,
Angela

Thank you Olivia, I'll try that today. Best regards, Angela
Support Team
Support Team posted this 30 January 2017

You're welcome.
Please keep us posted about the progress.

Thank you,
Olivia

You're welcome. Please keep us posted about the progress. Thank you, Olivia
Seagull
111 Posts
Seagull posted this 24 February 2017

Sorry for the delay in replying but I had to put that project on the back burner to attend to a more urgent account.

I realise that this is really Woocommerce issue but I am reporting here to hopefully help others. I have tried adding the above code to a CMS control in my theme but unfortunately it outputted the cost as 0. However in the Woocommerce install there are several flat rate Shipping Classes so that is probably what has broken it somewhere.

Regards,
Angela

Sorry for the delay in replying but I had to put that project on the back burner to attend to a more urgent account. I realise that this is really Woocommerce issue but I am reporting here to hopefully help others. I have tried adding the above code to a CMS control in my theme but unfortunately it outputted the cost as 0. However in the Woocommerce install there are several flat rate Shipping Classes so that is probably what has broken it somewhere. Regards, Angela
Support Team
Support Team posted this 27 February 2017

Hi,

I suggest that you search for existing solution for the similar questions on WordPress forums. If you find the solution which works with default WP theme we'll help you to get it work with Themler themes.

Thank you,
Olivia

Hi, I suggest that you search for existing solution for the similar questions on WordPress forums. If you find the solution which works with default WP theme we'll help you to get it work with Themler themes. Thank you, Olivia
janiecarmody
82 Posts
janiecarmody posted this 20 March 2026

Setting up WooCommerce shipping price can feel confusing at first, especially when different zones, weights, and delivery methods come into play. While managing store settings, situations like coordinating with a barrel shipping company to jamaica can make you realize how important accurate pricing rules really are. Small adjustments in shipping calculations can make a big difference in keeping things fair and predictable. It helps to test different scenarios and see how costs appear during checkout to avoid surprises. Keeping the process simple and clear makes handling orders and shipping expectations much easier over time.

Setting up WooCommerce shipping price can feel confusing at first, especially when different zones, weights, and delivery methods come into play. While managing store settings, situations like coordinating with a [barrel shipping company to jamaica][1] can make you realize how important accurate pricing rules really are. Small adjustments in shipping calculations can make a big difference in keeping things fair and predictable. It helps to test different scenarios and see how costs appear during checkout to avoid surprises. Keeping the process simple and clear makes handling orders and shipping expectations much easier over time. [1]: https://www.omlinternationalshipping.com/shipping-barrels-jamaica/
You must log in or register to leave comments