WooCommerce Show Product-Specific Content Under Loop Item Title

WooCommerce product custom field data showing between title and price on loop item

Pre-Requisites

There are no pre-requisites in order for you to be able to implement this solution.

How To Implement This Solution?

Simply copy the pre-coded solution to your active theme’s functions.php or preferably the Code Snippets Plugin.

About this Solution

Do you want to be able to display product specific information under the title and above the price on the loop item which appears on the product archive page? Maybe you want to let customers know of some important information from the category page before they drill-down to the product page itself. This quick guide shows you how you can generate a custom field for products, then display the data from said custom field between the product title and price on the loop item.

				
					/**
 * Snippet Name:     WooCommerce Custom Product Metabox For Content Between Title And Price On Loop Item
 * Snippet Author:   ecommercehints.com
*/

add_action ('woocommerce_product_options_advanced', 'ecommercehints_product_data_metabox');
function ecommercehints_product_data_metabox() {
   echo '<div class="options_group">';
   woocommerce_wp_text_input (array (
      'id'                => 'custom_loop_content_under_title',
      'value'             => get_post_meta (get_the_ID(), 'custom_loop_content_under_title', true),
      'label'             => 'Custom Loop Content',
      'description'       => 'Text to appear between title and price on the loop item'
  ));
   echo '</div>';
}

add_action ('woocommerce_process_product_meta', 'ecommercehints_save_field_on_update', 10, 2);
function ecommercehints_save_field_on_update ($id, $post) {
      update_post_meta ($id, 'custom_loop_content_under_title', $_POST['custom_loop_content_under_title']);
}

add_action( 'woocommerce_after_shop_loop_item_title', 'ecommercehints_woocommerce_after_shop_loop_item_title', 1, 0 );
function ecommercehints_woocommerce_after_shop_loop_item_title() {
global $product;
$custom_loop_content_under_title = $product->get_meta ('custom_loop_content_under_title');
echo $custom_loop_content_under_title;
};
				
			
WooCommerce Conversion Rate Optimisation (CRO) eBook
100 WooCommerce Conversion Rate Optimisation Tips

Leave a Reply

If you are going to write code in the comments, please wrap it between code tags.

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

Other Recent Guides

Subscribe To Emails

Get exclusive WooCommerce tips that I only share with email subscribers

Join hundreds of other subscribers