Overwrite Woocommerce JS

I recently had to change certain parts of the WooCommerce Javascript. It would be bad to edit the JS provided with the plugin as it would be overwritten by an upgrade. WooCommerce gives us an easy way of having custom templates but no matching, easy way of using custom Javascript.

I had to overwrite some functionality in the add-to-cart.js, so I created a new JS called /js/add-to-cart-kb-custom.js.
 This is how I did it in functions.php

</span>
function load_my_scripts() {
  wp_dequeue_script('wc-add-to-cart');
  wp_enqueue_script('wc-add-to-cart', get_bloginfo('stylesheet_directory'). '/js/add-to-cart-kb-custom.js' , array( 'jquery' ), false, true);
}
 
add_action('wp_enqueue_scripts', 'load_my_scripts');

 

Author: Kieran Barnes

Kieran is a PHP developer with 15 years commercial experience. Specialist in WordPress, CakePHP, CubeCart and all things PHP.

Leave a Reply

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