1

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

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

1 Answer 1

3

Just at a glance, wp.template is a method defined in /wp-includes/js/wp-util.js. It's included as a dependency when WooCommerce registers the wc-add-to-cart-variation script. You don't appear to be including wp-util as a dependency in your call to wp_register_script().

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.