Conflicts with acf select2 with woocommerce select2 on product page on backend
-
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
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.
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
but WooCommerce becomes unusable on product page
in fact:
with “selectWoo” script, fields not work
without “selectWoo” script, fields workWhat’s the solution then?
You must be logged in to reply to this topic.