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
 * @community     https://businessbloomer.com/club/
 */
 
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 custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

  • WooCommerce: Disable Variable Product Price Range $$$-$$$
    You may want to disable the WooCommerce variable product price range which usually looks like $100-$999 when variations have different prices (min $100 and max $999 in this case). With this snippet you will be able to hide the highest price, and add a “From: ” prefix in front of the minimum price. At the […]
  • WooCommerce: Hide Price & Add to Cart for Logged Out Users
    You may want to force users to login in order to see prices and add products to cart. That means you must hide add to cart buttons and prices on the Shop and Single Product pages when a user is logged out. All you need is pasting the following code in your functions.php (please note: […]
  • WooCommerce Visual Hook Guide: Archive / Shop / Cat Pages
    I’ve created a visual HTML hook guide for the WooCommerce Archive Page (which is the same page for the Shop, Category, Tag pages). This visual guide belongs to my “Visual Hook Guide Series“, that I’ve put together so that you can find WooCommerce hooks quickly and easily by seeing their actual locations (and you can […]
  • WooCommerce: Hide Prices on the Shop & Category Pages
    Interesting WooCommerce customization here. A client of mine asked me to hide/remove prices from the shop page and category pages as she wanted to drive more customers to the single product pages (i.e. increasing the click-through rate). As usual, a simple PHP snippet does the trick. I never recommend to use CSS to “hide” prices, […]
  • WooCommerce: How to Remove the “Default Sorting” Dropdown
    If the WooCommerce product sorting functionality (“Default Sorting” dropdown) is a waste of space or you don’t need that select box at all, you may want to remove it. No matter if you prefer custom code or a simple plugin – hiding the product sorting dropdown is a piece of cake. Enjoy!

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. Follow @rmelogli

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?

    Thanks,
    Darren

    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!

      https://businessbloomer.com/woocommerce-visual-hook-guide-single-product-page/

    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
    https://docs.woocommerce.com/document/display-product-dimensions-on-archive-pages/

    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? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. 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 the Business Bloomer Club to get quick WooCommerce support. Thank you!

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