Woocommerce 2.x: Using your own assets js

Instead of hacking the js files under assets/js, its better to create one yourself. Say you want to modify assets/js/frontend/checkout.js for example, in your theme functions.php

/**
 * use our own checkout js in the proper way
 * @return null
 */
function use_custom_js() {
  global $woocommerce;
  // make sure its checkout page
  if (is_checkout()) {
    wp_dequeue_script('wc-checkout');
    // create assets/js/frontend/ dir under your theme dir.
    wp_enqueue_script( 'wc-checkout-my', dirname(get_stylesheet_uri()).'/assets/js/frontend/checkout.js', array( 'jquery', 'woocommerce' ), $woocommerce->version, true );
  }
}
add_action('wp_enqueue_scripts', 'use_custom_js');

Author: bpeh

Bernard Peh is a great passioner of web technologies and one of the co-founder of Sitecritic.net Website Design and Reviews. He works with experienced web designers and developers everyday, developing and designing commercial websites. He specialises mainly in SEO and PHP programming.