Support » Plugin: WooCommerce » Customise WooCommerce wc-add-to-cart (add-to-cart.js)

  • Resolved lnorton059



    I want to customise wc-add-to-cart (js/frontend/add-to-cart.js) and add a jQuery ‘addClass’ to the add to cart trigger. I’ve got this working when overwriting the original file but obviously this is bad practice so I am using the dequeue and enqueue process. However, I am having problems with the enqueued script. The script is loading but the ajax add to cart has been lost and instead the page is refreshing on every add.

    I am using the following script to dequeue and enqueue my script:

    add_action('wp_enqueue_scripts', 'override_woo_frontend_scripts');
    function override_woo_frontend_scripts() {
        wp_enqueue_script('wc-add-to-cart', get_template_directory_uri() . '/woocommerce/js/add-to-cart.js', array('jquery', 'woocommerce', 'wc-country-select', 'wc-address-i18n'), null, true);

    I’ve tried enqueuing the script with a different name, such as wc-add-to-cart2.

    I’ve also tried loading the script straight into the header.php but I encounter the same problems.

    The only way it works is to overwrite the original file.

    Would anyone happen to know why it is doing this?

    Thank you

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • I’ve just added the full path to the js file and it seems to now work.

    There must be a problem with get_template_directory_uri() which thinks my template directory is something other than what it is currently set to.


Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Customise WooCommerce wc-add-to-cart (add-to-cart.js)’ is closed to new replies.