Support

Account

Home Forums Backend Issues (wp-admin) ACF on product variations: almost works Reply To: ACF on product variations: almost works

  • Found a solution for ACF fields requiring events to be attached.

    In your php code, add the following:

    function xxx_admin_head_post() {
    	global $post_type;
    	if ($post_type === 'product') {
    		wp_register_script( 'xxx-acf-variation', get_template_directory_uri() . '/js/acf-variation.js', array(
    			'jquery-core',
    			'jquery-ui-core'
    		), '1.1.0',
    			true ); // Custom scripts
    		
    		wp_enqueue_script( 'xxx-acf-variation' ); // Enqueue it!
    
    	}
    }
    
    /* actions fired when adding/editing posts or pages */
    /* admin_head-(hookname) */
    add_action( 'admin_head-post.php', 'xxx_admin_head_post' );
    add_action( 'admin_head-post-new.php',  'xxx_admin_head_post' );

    Create js/acf-variation.js with the following code:

    jQuery(document).ready(function($) {
        $( '#woocommerce-product-data' ).on( 'woocommerce_variations_loaded', function(){
            acf.doAction('ready');
        });
    });