Home › Forums › General Issues › ACF – WooCommerce – Product Variation › Reply To: ACF – WooCommerce – Product Variation
John, and those struggling to piece together the different parts of this solution together, Here is how to display it on the ‘single-product.php’ page.
Add the following, or similar, function to ‘functions.php’.
/*----------------------------------------------*/
/* Displays ACF fields 'Frame Type' and 'Lens Type'
/* Displays on SINGLE PRODUCT page and QUICK VIEW via archive
/* DEPENDENCIES: ACF Custom Fields
/* $variations are outputted by "variation.php"
/*----------------------------------------------*/
function frame_style_lens_colour ( $variations ) {
$variations['frame_type'] = get_field('frame_type', $variations[ 'variation_id' ]);
$variations['lens_type'] = get_field('lens_type', $variations[ 'variation_id' ]);
return $variations;
}
add_filter ( 'woocommerce_available_variation', 'frame_style_lens_colour ', 10, 1 );
THEN copy ‘variation.php’ to your theme or child theme.
Add the following to the file, or similar, and save it:
<p><strong>Lens Style:</strong> {{{ data.variation.lens_type }}} Polarized Lens </p>
<p><strong>Frame Style:</strong> {{{ data.variation.frame_type }}} </p>
Now your variation specific ACF fields will appear on the front end of the website.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.