• wpdavid

    (@wpdavid)


    I want to customize add-to-cart-variation.js for WooCommerce 2.1.5, but I’m having trouble understanding what “woocommerce_variation_select_change” refers to in this section of code:

    .on( ‘change’, ‘.variations select’, function( event ) {

    $variation_form
    .trigger( ‘woocommerce_variation_select_change’ )
    .trigger( ‘check_variations’, [ ”, false ] );

    It reads as if “woocommerce_variation_select_change” is a jQuery event type, but I’ve searched through a bunch of WooCommerce .js and .php files (add-to-cart.js, add-to-cart-variation.js, single-product.js, woocommerce.js, wc-cart-functions.php, wc-core-functions.php, wc-product-functions.php, class-wc-cart.php, and class-wc-ajax.php) and I can’t find it being defined as an event, or any reference to it whatsoever – so, I have no idea what code is being run with the .trigger.

    The same holds true for the second .trigger, “check_variations”, but at least I see it referenced later in add-to-cart-variation.js, so I know what code is being run.

    Is there something I’m missing in the way WooCommerce defines and uses event types?

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hey wpdavid! I have the exact same problem. Did you find a solution yet? I’m curious!

    Hi.
    May be this topic is quite old but i just would like to point that woocommerce_variation_select_change is a name for some trigger that, afaik, it is not being used at all in add-to-cart-variation.js.
    The select change just triggers in add-to-cart-variation.js, line 69 or so:

    // Upon changing an option
    .on( 'change', '.variations select', function( event ) {
    
    $variation_form = $( this ).closest( '.variations_form' );
    $variation_form.find( 'input[name=variation_id]' ).val( '' ).change();
    
    $variation_form
    	//.trigger( 'woocommerce_variation_select_change' )
    	.trigger( 'check_variations', [ '', false ] );
    
    [...]

    Simply comment out that line and variations are working as expected.
    So if you want to poke into add-to-cart-variation.js IMHO you should only take care of check_variations trigger (on line 99 or so)

    Regards, Cancrexo

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WooCommerce | Customize add-to-cart-variation.js’ is closed to new replies.