We already talked about displaying an ACF field on the single product page. This time around, we’ll do the exact same but for the product loop pages (shop, category, tag, etc.). ACF (Advanced Custom Fields) is an awesome plugin to create and manage custom fields, so this is definitely a tutorial that will help many WooCommerce developers.
Please note that if ACF is not active, the snippet will break the site. There is a way to make it trigger only when ACF plugin is active, just so you know. Anyway, let’s see how we can display the value of a product ACF inside the loop. Enjoy!
PHP Snippet: Show Product ACF @ WooCommerce Shop / Loop Pages
Note: please change the ACF field ID inside the get_field function to your own custom field ID. In my case I’ve used a custom field ID called “warranty“.
/**
* @snippet Product ACF @ Shop
* @how-to businessbloomer.com/woocommerce-customization
* @author Rodolfo Melogli, Business Bloomer
* @testedwith WooCommerce 6
* @community https://businessbloomer.com/club/
*/
add_action( 'woocommerce_before_shop_loop_item_title', 'bbloomer_acf_loop' );
function bbloomer_acf_loop() {
global $product;
$warranty = get_field( 'warranty', $product->get_id() );
if ( ! $warranty ) return;
echo '<div><i>' . $warranty . '</i></div>';
}