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');
});
});
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.