This is a Developer level doc. If you are unfamiliar with code and resolving potential conflicts, select a WooExpert or Developer for assistance. We are unable to provide support for customizations under our Support Policy.
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+
↑ Back to top
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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
↑ Back to top
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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>'; | |
} | |
} |