Modify Woocommerce Javascript

The context:
I have a bunch of product variations with 2-3 different attributes, but one is the “main one” while the others are all unique once the main attribute is selected, so I need to auto-select them on change of the main one (and probably hide the dropdowns with css).

I’ve copied the corresponding file into my theme and made an override

Read More
wp_deregister_script('wc-add-to-cart-variation');
wp_register_script('wc-add-to-cart-variation', get_bloginfo(  'stylesheet_directory' ). '/js/add-to-cart-variation.js' , array( 'jquery' ), WC_VERSION, TRUE);
wp_enqueue_script('wc-add-to-cart-variation');

This is working correctly, but it throws an error:

Uncaught TypeError: wp.template is not a function

I’ve made no changes to the file so far, so I’m expecting it to work correctly since I’m swapping a file with an identical one at the moment, but I’m clearly missing something…

Thanks a lot in advance to all of you

PS. EDIT:

This are the first bunch of rows from add-to-cart-validation.js where the error is thrown in case it could help.

;(function ( $, window, document, undefined ) {

$.fn.wc_variation_form = function() {
    var $form                  = this,
        $single_variation      = $form.find( '.single_variation' ),
        $product               = $form.closest( '.product' ),
        $product_id            = parseInt( $form.data( 'product_id' ), 10 ),
        $product_variations    = $form.data( 'product_variations' ),
        $use_ajax              = $product_variations === false,
        $xhr                   = false,
        $reset_variations      = $form.find( '.reset_variations' ),
        template               = wp.template( 'variation-template' ),
        unavailable_template   = wp.template( 'unavailable-variation-template' ),
        $single_variation_wrap = $form.find( '.single_variation_wrap' );

Related posts

1 comment

Comments are closed.