Support

Account

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.