• Resolved HB

    (@hbazan85)


    Hello

    I’ve noticed this bug (Woo latest version and ACF Pro latest version):

    I’m using a taxonomy field and the filter to display images in the select element.

    PHP

    // Enhance ACF Field Thumbnails + HTML in Admin Select2
    add_action('acf/input/admin_enqueue_scripts', function () {
    wp_enqueue_script(
    'acf-esc-markup-fields-js',
    get_template_directory_uri() . '/assets/js/acf-esc-markup-fields.js',
    array('jquery'),
    '1.0.0',
    true
    );
    });

    if (!function_exists('render_taxonomy_thumbnail')) {

    function render_taxonomy_thumbnail($title, $term, $prefix) {
    $thumb_id = get_field('thumbnail_taxonomy', "{$prefix}{$term->term_id}", false);
    if ($thumb_id) {
    $img = wp_get_attachment_image($thumb_id, 'thumbnail', "", ['class' => 'acf-tax-image']);
    } else {
    $img = default_img_placeholder();
    }

    $title = '

    ' . $img . '' . $title;

    return wp_kses_post($title);
    }

    // Mapping of ACF field name => meta prefix
    $acf_tax_fields = [
    // fields
    'artist_select' => 'artist_',
    ];

    // Dynamically register filters
    foreach ($acf_tax_fields as $field => $prefix) {
    add_filter("acf/fields/taxonomy/result/name={$field}", function($title, $term) use ($prefix) {
    return render_taxonomy_thumbnail($title, $term, $prefix);
    }, 10, 2);
    }

    }

    JS

    (function($) {
    $('#acf-field_61fd86bec0344').addClass('vibrawp-taxonomy-field');
    acf.add_filter('select2_escape_markup', function(escaped, original, $select, settings, field) {
    const fields=[ "artist_select"];
    return fields.includes(field.data('name')) ? original : escaped;
    });
    })(jQuery);

    In a common post, everything appears normal there and works

    https://prnt.sc/8xhw-oGErxaf

    However, when I go to WooCommerce product page and use same fields, there’s an apparent conflict with the WooCommerce Select2 element, which overlaps with the ACF Select2 element, they annoy each other, incorrectly displaying the same content.

    https://prnt.sc/LtTdyLJpuKlt

    I’ve demonstrated this by removing all traces of the WooCommerce Select2 element.

    function dequeue_select2_selectwoo() {

    if ( class_exists( 'woocommerce' ) ) {

    wp_deregister_script('selectWoo');

    }
    }
    add_action( 'admin_enqueue_scripts', 'dequeue_select2_selectwoo', 100 );

    It displays correctly there without the “selectWoo” script

    https://prnt.sc/hGgK0-uDuEwZ

    but WooCommerce becomes unusable on product page

    in fact:

    with “selectWoo” script, fields not work
    without “selectWoo” script, fields work

    What’s the solution then?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Sai (woo-hc)

    (@saivutukuru)

    Hi @hbazan85,

    Thanks for the detailed report and code snippets. This is helpful.

    What you’re seeing is a known type of conflict between ACF’s Select2 usage and WooCommerce’s selectWoo (its Select2 fork), which loads only on WooCommerce admin screens, like the product editor.

    Removing selectWoo works because ACF then falls back to native Select2, but as you’ve noticed, that’s not a viable solution since WooCommerce depends on it.

    Before jumping to a fix, a few things would help narrow this down:

    • Does this happen only on product edit pages, or also on other WooCommerce admin screens?
    • Are you targeting the select2_escape_markup filter globally, or only for specific ACF fields?
    • Are you initializing or modifying Select2 before or after WooCommerce initializes selectWoo?

    In most cases, the solution involves scoping the Select2 customization to ACF fields only, or conditionally disabling the custom filter when selectWoo is in use, rather than deregistering it.

    Once we confirm the scope, we can look at a safer workaround.

    Thread Starter HB

    (@hbazan85)

    hello

    1 – only on product edit page

    2 – on specific ACF field, a taxonomy field (artist_select)

    3 – before WooCommerce inits SelecWoo

    Plugin Support shahzeen(woo-hc)

    (@shahzeenfarooq)

    Hi there!

    Thanks for confirming those details that helps clarify things.

    Since this issue:

    • Occurs only on the WooCommerce product edit screen
    • Involves custom PHP and JavaScript modifications
    • Relies on ACF Pro’s Select2 behavior and initialization timing

    this falls outside the scope of support we’re able to provide for WooCommerce core.

    WooCommerce relies on selectWoo for core admin functionality, and we’re not able to advise on altering, overriding, or conditionally bypassing it for third-party or custom Select2 implementations. The behavior you’re seeing is the result of how ACF Pro integrates Select2 alongside WooCommerce’s selectWoo, which is something the ACF Pro team is best positioned to review and guide you on.

    At this point, we recommend reaching out to ACF Pro support, They can advise on a supported way to scope or adjust the customization so it works alongside selectWoo.

    Also, If you need more in-depth support or want to consider professional assistance for customization, I can recommend WooExperts and Codeable.io as options for getting professional help.

    Alternatively, you can also ask your development questions in the  WooCommerce Community Slack as custom code falls outside our usual scope of support

    Plugin Support thelmachido a11n

    (@thelmachido)

    It’s been a while since this thread has had any activity for this reason we are closing this thread. 

    If WooCommerce has been useful for your store and you appreciate the support you’ve received, we’d truly appreciate it if you could leave us a quick review here: 

     https://ww.wp.xz.cn/support/plugin/woocommerce/reviews/#new-post

    Feel free to open a new forum topic if you run into any other problem. 

    Thread Starter HB

    (@hbazan85)

    Hello

    I wrote to ACF Pro and gave them my own code solution to consider for next updates, but the definitive solution should come from there; no one has seriously addressed this problem.

    Plugin Support Frank Remmy (woo-hc)

    (@frankremmy)

    Hi @hbazan85,

    Thanks for the update, and I appreciate you taking the time to investigate this further.

    Since you’ve already reached out to ACF Pro and provided them with a potential solution, that’s definitely the right next step. The conflict you’re seeing occurs because both ACF and WooCommerce load their own versions of Select2 on the product edit screen, and WooCommerce relies on SelectWoo for core functionality in the admin. Because of that dependency, we’re limited in how much we can safely modify or override on our side without risking regressions elsewhere.

    If ACF is able to adjust how their Select2 instance initializes on WooCommerce product pages, that would provide the most stable long‑term fix. In the meantime, your temporary workaround is a good way to keep things running smoothly.

    If anything changes on their end or you need help reviewing their proposed solution once they respond, feel free to share an update and we’ll be happy to take another look.

Viewing 6 replies - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.