WooCommerce: Display Product Height, Length, Width @ Shop Page

Another interestng snippet that could come very handy. How do we show product dimensions on the shop / category / tag / loop pages?

WooCommerce: show height, width, length @ loop

PHP Snippet: Display Product Height, Length, Width @ Shop Page – WooCommerce

 * @snippet       Display Product Height, Length, Width @ Shop Page - WooCommerce
 * @how-to        Get CustomizeWoo.com FREE
 * @sourcecode    https://businessbloomer.com/?p=21982
 * @author        Rodolfo Melogli
 * @compatible    WC 2.6.14, WP 4.7.2, PHP 5.5.9

add_action( 'woocommerce_after_shop_loop_item', 'bbloomer_show_product_dimensions_loop', 20 );

function bbloomer_show_product_dimensions_loop() {
global $product;
$dimensions = $product->get_dimensions();
if ( ! empty( $dimensions ) ) {
echo '<div class="dimensions"><b>Height:</b> ' . $product->get_height() . get_option( 'woocommerce_dimension_unit' );
echo '<br><b>Width:</b> ' . $product->get_width() . get_option( 'woocommerce_dimension_unit' );
echo '<br><b>Length:</b> ' . $product->get_length() . get_option( 'woocommerce_dimension_unit' );
echo '</div>';


Where to add this snippet?

You can place PHP snippets at the bottom of your child theme functions.php file (before "?>" if you have it). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my free video tutorial "Where to Place WooCommerce Customization?"

Does this snippet (still) work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7+.

If you think this code saved you time & money, please join other Business Bloomer supporters and avail of 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce Customization?

Check out these free video tutorials. You can start learning how to customize WooCommerce without unnecessary plugins. Watch me code and learn by example!

  • how-to-edit-woocommerce-with-php-snippets
  • woocommerce-hooks-add_action-list-visual
  • woocommerce-customize-single-product-page-PHP

Rodolfo Melogli

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as a WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza.

23 thoughts on “WooCommerce: Display Product Height, Length, Width @ Shop Page

  1. Hi,

    This is great. How can we display attributes? For example, I have a “Size” attribute that I would like to display in the loop.

    I guess small changes in your code would do the job?

    1. Hi Ahmed, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  2. Useful function. Thanks!

    1. You’re welcome Slavi ๐Ÿ™‚

  3. It worked for me. Thank’s a lot!

  4. Great, just what I needed to show the dimensions on the short description without using the tabs and it also fixed the direction problem with the units

    1. Great to hear that Rubb ๐Ÿ™‚

    2. Oh please! Tell me how? I thought using ‘woocommerce_before_main_content’ instead of ‘woocommerce_after_shop_loop_item’ would do it, but no…

    3. Oh wow, nevermind… I just found a very useful hook visual guide right here. That’s awesome Rodolfo!


    4. How about variable products though?

      1. That’s a little more complex. Also, which variation would you pick? Maybe it should be disabled for variable products ๐Ÿ™‚

  5. Hi,
    I found the answer to my own question. In woocommerce 3 get_dimensions() is deprecated. Besides throwing an error the old way is not empty anymore when there are no dimensions, they actually return N/A which means that displays. Hope this helps others. In your code example

    the lines

    $dimensions = $product->get_dimensions();
            if ( ! empty( $dimensions ) )

    change to

    $dimensions = wc_format_dimensions($product->get_dimensions(false));
            if ( $product->has_dimensions() )

    reference for this is here

    1. Excellent, thank you so much Mark!

  6. Hi, I have been using $product->get_dimensions(); in my functions file for a long time. I turned on debug recently when working on something else on got this notice…
    “Notice: WC_Product::get_dimensions was called with an argument that is deprecated since version 3.0! By default, get_dimensions has an argument set to true so that HTML is returned. This is to support the legacy version of the method. To get HTML dimensions, instead use wc_format_dimensions() function”

  7. This works great for my shop but how would I apply it to only one specific category and not all products? For example if I only want to show dimensions for baths and not chemicals?

      1. Perfect!! Thank you so much!

  8. Hi,

    The snippet works beautifully.I would like know how to do like if we click on an icon it would display the dimensions or hover on icon it would display the dimensions. instead of showing it directly. i guess it would add more style to the shop page as well.

    thanks kavi

    1. Hey KAVIARASU, thanks for your comment! You can do that with some CSS styling, unfortunately this is custom work and I cannot provide a complementary solution here on the blog. Thanks a lot for your understanding! ~R

Questions? Feedback? Support? Leave your Comment Now!

If you are writing code, please wrap it between: [php]code_here[/php]. Failure to complying with this (as well as going off topic) will result in comment deletion. You should expect a reply in about a week - this is a popular blog but I need to get paid work done first. Please consider joining #BloomerArmada to ask me 1-to-1 WooCommerce questions. Thank you :)

Your email address will not be published. Required fields are marked *