Display product dimensions on archive pages

You are here:

You need to add this code to your child theme’s functions.php file or via a plugin that allows custom functions to be added, such as the Code snippets plugin. Please don’t add custom code directly to your parent theme’s functions.php file as this will be wiped entirely when you update the theme.

Display WooCommerce product dimensions on archive pages, below the title of the product.

WooCommerce version 3.0+

  /**
  * Show product dimensions on archive pages for WC 3+
  */
  add_action( ‘woocommerce_after_shop_loop_item’, ‘rs_show_dimensions’, 9 );
   
  function rs_show_dimensions() {
  global $product;
  $dimensions = wc_format_dimensions($product->get_dimensions(false));
   
  if ( $product->has_dimensions() ) {
  echo ‘<div class=”product-meta><span class=”product-meta-label>Dimensions: </span>‘ . $dimensions . ‘</div>‘;
  }
  }

WooCommerce version lower than 3.0

  /**
  * Show product dimensions on archive pages WC 3 and below
  */
  add_action( ‘woocommerce_after_shop_loop_item_title’, ‘wc_show_dimensions’, 9 );
   
  function wc_show_dimensions() {
  global $product;
  $dimensions = $product->get_dimensions();
   
  if ( ! empty( $dimensions ) ) {
  echo ‘<span class=”dimensions>‘ . $dimensions . ‘</span>‘;
  }
  }
Was this article helpful?
Dislike 0
Views: 13