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 '';
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 '';
}
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 . '
';
};