1

How can I replace the WooCommerce page-specific .js files with my own versions? For example on the cart page there's /plugins/woocommerce/assets/js/frontend/cart.min.js but I'd like to load /themes/mythem/woocommerce/js/cart.min.js in its place.

2

It's common to find theme that you can't simply override certain file by mirroring the file structure in your child theme.

In this case the cart.min.js is most likely included via wp_queue_script so you gotta find the handle of the script by looking at the source code of WooCommerce (just search by wp_enqueue_script). Then you can run wp_dequeue_script on that handle.

Lastly, you run wp_enqueue_script on your own js file to include it in your template.

  • Yes, the rub with WC is that there's a bunch of logic to conditionally enqueue the scripts based on the page context. So I'm not sure how maintainable this will be. – Colin May 28 '13 at 17:15
1

First You should remove a registered script, register a new script then enqueue a script.

Check the following scripts to replace checkout.min.js with custom checkout script.


add_action( 'wp_enqueue_scripts', 'shopkeeper_wp_enqueue_scripts_for_frontend', 99 );
function shopkeeper_wp_enqueue_scripts_for_frontend(){
    if( is_checkout() ){
        // Checkout Page        
        wp_deregister_script('wc-checkout');
        wp_register_script('wc-checkout', SHOPKEEPER_JS_PATH . "override_checkout.js", 
        array( 'jquery', 'woocommerce', 'wc-country-select', 'wc-address-i18n' ), WC_VERSION, TRUE);
        wp_enqueue_script('wc-checkout');
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.