Show Product Dimensions in WooCommerce

For some strange reason the WooCommerce WordPress e-commerce plugin has options in the product admin to add a product’s Weight and Dimensions but then doesn’t show these values on the front end like some might expect. Not 100% sure if it’s a theme clash or WooCommerce bug/oversight but WooCommerce told me there’s a workaround involving product attributes. I couldn’t get this working however.

Here’s what does work though. To show product dimensions on archive pages, add the following code to your theme’s functions.php file or in a new wordpress plugin:

[php]add_action( ‘woocommerce_after_shop_loop_item_title’, ‘cj_show_dimensions’, 9 );

function cj_show_dimensions() {
global $product;
$dimensions = $product->get_dimensions();

if ( ! empty( $dimensions ) ) {
echo ‘<span class="dimensions">’ . $dimensions . ‘</span>’;
}
}[/php]

You can change the “get_dimensions” to “get_weight” if you want to show a products weight instead or additionally in a new function.

NOTE: The above code will show dimensions on archive pages like Categories, Recently Added Products, etc. If you want to show it on single product details pages, there are other WooCommerce hooks but the ones I tried wouldn’t work with my theme. If you don’t mind editing your theme files directly, adding something like this to the template file that shows the individual products, something like ‘single-product.php’, should work too:

[php]
<div class="dimensions">
<strong>Dimensions</strong>: <!–?php echo $_product—>get_dimensions(); ?>
</div>
[/php]

Don’t forget to add a .dimensions class to your theme’s css file to style the results if required.