Do you want to be able to display product specific information under the add to cart button on the product 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 under the add to cart button on the loop item.
/**
* Snippet Name: WooCommerce Custom Product Metabox For Content Under Add To Cart Button On Loop Item
* 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_under_button',
'value' => get_post_meta (get_the_ID(), 'custom_loop_content_under_button', true),
'label' => 'Custom Loop Content',
'description' => 'Text to appear below the add to cart button on the 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_under_button', $_POST['custom_loop_content_under_button']);
}
add_action( 'woocommerce_after_shop_loop_item', 'ecommercehints_woocommerce_after_shop_loop_item' );
function ecommercehints_woocommerce_after_shop_loop_item() {
global $product;
$custom_loop_content_under_button = $product->get_meta ('custom_loop_content_under_button');
echo ''.$custom_loop_content_under_button.'
';
};