Product Archive

WooCommerce Display Product-Unique Content On Loop Items

WooCommerce custom metabox field data showing on product loop

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

This guide shows you how you can display product-specific content on the loop items which are shown on the product archive page. You may wish to show an offer you are running or the billing cycle for a particular product. This guide shows you how to create a product metabox to enter unique content then display it on the loop above the add to cart button

/**
 * Snippet Name:     WooCommerce Custom Product Data Metabox For Custom Loop Item Text
 * 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',
      'value'             => get_post_meta (get_the_ID(), 'custom_loop_content', true),
      'label'             => 'Custom Loop Content',
	  'desc_tip'		  => true,
      'description'       => 'Text to appear on the product 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', $_POST['custom_loop_content']);
}

add_action( 'woocommerce_after_shop_loop_item', 'ecommercehints_woocommerce_after_shop_loop_item', 1, 0 );
function ecommercehints_woocommerce_after_shop_loop_item() {
global $product;
$custom_loop_content = $product->get_meta ('custom_loop_content');
echo $custom_loop_content . '<br><br>';
};

Snippet Benefits

  • Let customers know of a special offer you are running for a particular product.
  • Show literally any product-specific content you like from a higher level category page on the loop items.

100 WooCommerce Conversion Rate Optimisation Tips

This field is for validation purposes and should be left unchanged.

Let’s collaborate!

Need to outsource WordPress development?

Join forces with UnlimitedWP for an outsourced white label web development service you can truly rely on.

First Timer Here?

Sign up to receive 20% off on your first month with us.

26027
WELCOME OFFER