Home » WooCommerce: Display Product ACF Value @ Shop Page

WooCommerce: Display Product ACF Value @ Shop Page

by adminkys

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!

With the PHP snippet below, it was super easy to display additional information in the shop page, and specifically a product custom field by ACF plugin.

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        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @testedwith    WooCommerce 6
 * @donate $9     https://www.tutoraspire.com
 */

add_action( 'woocommerce_before_shop_loop_item_title', 'tutoraspire_acf_loop' );

function tutoraspire_acf_loop() {
global $product;
$warranty = get_field( 'warranty', $product->get_id() );
if ( ! $warranty ) return;
echo '
' . $warranty . '
'; }

You may also like