WooCommerce: Display Height, Length, Width @ Shop Page

Another interesting snippet that could come very handy. How do we show the product dimensions (height, width, length) in the shop / category / tag / loop pages? This could be a handy trick for shops that calculate shipping rates based on volume, or when the volume is a vital piece of data customers need to know before proceeding further. Either way, enjoy!

WooCommerce: show product height, width, length @ loop

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

 * @snippet       Display Product Height, Length, Width @ Shop Page - WooCommerce
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 3.9
 * @donate $9     https://businessbloomer.com/bloomer-armada/
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>';        
Was this article helpful?

Where to add custom code?

You should place PHP snippets at the bottom of your child theme functions.php file and CSS at the bottom of its 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 guide "Should I Add Custom Code Via WP Editor, FTP or Code Snippets?" and my video tutorial "Where to Place WooCommerce Customization?"

Does this snippet (still) work?

Please let me know in the comments if everything went 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.

If you think this code saved you time & money, feel free to join 17,000+ WooCommerce Weekly subscribers for blog post updates and 250+ Business Bloomer supporters for 365 days of WooCommerce benefits. Thank you in advance!

Need Help with WooCommerce?

Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent 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.

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

  1. Thank you, this was just what I was looking for.

  2. Hey there, is it possible to show dimensions in CM and Inches at the same time? So ideal enter in CM but convert and show in CM and Inches in the front end?


    1. Hi Darren, 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!

  3. 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!

  4. Useful function. Thanks!

    1. You’re welcome Slavi ๐Ÿ™‚

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

  6. 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 ๐Ÿ™‚

  7. 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!

      1. You’re welcome Iggy!

  8. 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”

  9. 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!

  10. 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 shortcodes: [php]code_here[/php]. Failure to complying with this (as well as going off topic, not writing in English, etc.) will result in comment deletion. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining BloomerArmada to get blog comment reply priority, ask me 1-to-1 WooCommerce questions and enjoy many more perks. Thank you :)

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