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.

Advertisements

Published by

Leon Quinn

Multimedia Design company in Leitrim, Ireland specializing in WordPress Website Design, Photoshop and Graphics. www.reverbstudios.ie

5 thoughts on “Show Product Dimensions in WooCommerce”

  1. I had exactly the same problem with the product dimensions not being shown on the product page. I edited the suggested code and came up with this, which you should put in your functions.php…

    /*
    * Display WooCommerce product dimension on product page
    */
    add_action( 'woocommerce_single_product_summary', 'cj_show_dimensions', 9 );
    function cj_show_dimensions() {

    global $product;
    $width = $product->width;
    $height = $product->height;

    if ( !empty($width) && !empty($height) ) {
    echo '<span class="dimensions">' . $width . ' x ' . $height . '</span>';
    }
    }

    Like

  2. Product dimensions aren’t displayed on archive pages because that’s what product details pages are for.

    Stores displaying dimensions on archives are exceptions to the norm… So it’s not really strange 😉

    Like

    1. Well in this case the dimensions weren’t showing on the product detail page either and none of the other WooCommerce hooks I could find to make them show there worked so the archive pages are pretty much the only place I could get them showing. Better than nowhere!

      Like

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s