jQuery dependent script ignores $in_footer bool and doesn’t work in header

My plugin uses the following to enqueue script in jQuery dependency:

wp_enqueue_script( $plugin_short_slug, plugins_url() . ‘/’ . $plugin_slug . ‘/js/’ . $plugin_slug . ‘.js’, ”, array(‘jquery’), ”, true);

If I use it on child theme where I dequeue default WordPress jQuery and load jQuery from CDN in footer, both jQuery and my script land in footer and it works correctly.

Unfortunately when I use plugin on default theme, where default WordPress jQuery is loaded in header, $in_footer is ignored, script appears in header after jQuery and doesn’t work despite no errors in console.

I wouldn’t like to replace default jQuery or even move it to the footer, because it can break other things for users.

My script is the following, phpVars is properly passed in localized script above:

var timeout;

jQuery(‘div.woocommerce’).on(‘change’, ‘.qty’, function(){
if (timeout != undefined) clearTimeout(timeout);
timeout = setTimeout(function() {
jQuery(‘[name=”update_cart”]’).trigger(‘click’);
}, phpVars.acau_update_delay );
});

Read more here:: jQuery dependent script ignores $in_footer bool and doesn’t work in header

Leave a Reply

Your email address will not be published. Required fields are marked *