WooCommerce – Show shipping cost on product page [closed]

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