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.
5 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
You must log in or register to leave comments