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');

Like it.? Share it:

Comments are closed.