Want to display product dimensions on product archive page in your woocommerce store? There are two ways to do this first is add below code snippets in functions.php page of your current theme OR you can also create a separate WordPress plugin to display product dimensions on archive page.
Below code will display woocommerce product dimensions, below product title on archive page. Add this in your functions.php page.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <?php add_action( 'woocommerce_after_shop_loop_item_title', 'fm_display_dimensions', 9 ); function fm_display_dimensions() { global $product; $dimensions = $product->get_dimensions(); if ( ! empty( $dimensions ) ) { echo '<span class="product-dimensions">' . $dimensions . '</span>'; } } ?> |
Create a folder named “WooCommerce-display-product-dimensions” in your root directory of website => wp-content => plugins folder then create a index.php page under this folder. Copy below code and paste in index.php page and save.
Now login in your admin panel and navigate to Plugins page. On the plugins page search “WooCommerce Display Product Dimensions” and activate to enable this features.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <?php /* Plugin Name: WooCommerce Display Product Dimensions Description: It will display product dimensions on archive pages. Version: 1.0 Author: freewebmentor Author URI: http://freewebmentor.com */ add_action( 'woocommerce_after_shop_loop_item_title', 'fm_display_dimensions', 9 ); function fm_display_dimensions() { global $product; $dimensions = $product->get_dimensions(); if ( ! empty( $dimensions ) ) { echo '<span class="product-dimensions">' . $dimensions . '</span>'; } } ?> |
Thank you for giving time on freewebmentor community. Please don’t forget to subscribe our newsletter or join us on Facebook to be the first to learn the next great thing from freewebmentor.
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: Best free Woocommerce plugins, Best WordPress Plugins, product Dimensions, woocommerce, woocommerce products, wordpress