WooCommerce – Show shipping cost on product page [closed]

I am developing an eCommerce site using WooCommerce for a client, and they want to be able to show the shipping cost of a product on the product page (because that’s what they have on their old store site).
Is there a way to do this? I’ve looked around and can’t find anything definitive, and although there is a similar question here on StackExchange, no one has answered the question.

I’m aware that there’s a $79 plugin to do this, but is there a way to set the shipping cost per item as well? Would rather avoid purchasing a plugin.

2 Answers
2

You can present the shipping costs per item in WooCommerce 2.x. enter image description here

Since you have set the prices as fixed and per item you can show them in the product description by simply writing them into the product description, or you can access the shipping class for the item (it’s a taxonomy) “product_shipping_class” that can be assigned to each product individually or via quick edit to all products.

How to show it in a product template? Each product page is divided up into a directory called woocommerce. You can copy that directory from the plug-in directory for Woocommerce directly into your theme folder. Once there you can make any changes without having future updates overwrite your theme changes. Here’s the link to the instructions for woocommerce theme files.

So you start with the ‘single-product.php’ page. This is the main loop for the single product page, and then ‘content-single-product.php’ which details the hooks within the product template.

Depending on where you want to display the shipping information you can now access the terms assigned to the product (in case you have different rates for different products). Use get_the_terms( $post->ID, ‘product_shipping_class’). For more information on working with call see this post.

Using some php to parse out the array you will know the shipping class and you can then display information about the shipping costs with a calculation based on the shipping class returned.

There are a few more ways to do this that involve the shipping class object, but this should get your started.

Leave a Comment