Where could I find an exhaustive list of javascript events defined by WooCommerce. ( Events like “woocommerce_variation_has_changed” )
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
On a hunt for the same I took a little dive into the JS source files.
Woocommerce Javascript events
Woocommerce Checkout JS events
$( document.body ).trigger( 'init_checkout' ); $( document.body ).trigger( 'payment_method_selected' ); $( document.body ).trigger( 'update_checkout' ); $( document.body ).trigger( 'updated_checkout' ); $( document.body ).trigger( 'checkout_error' ); $( document.body ).trigger( 'applied_coupon_in_checkout' ); $( document.body ).trigger( 'removed_coupon_in_checkout' );
Woocommerce cart page JS events
$( document.body ).trigger( 'wc_cart_emptied' ); $( document.body ).trigger( 'update_checkout' ); $( document.body ).trigger( 'updated_wc_div' ); $( document.body ).trigger( 'updated_cart_totals' ); $( document.body ).trigger( 'country_to_state_changed' ); $( document.body ).trigger( 'updated_shipping_method' ); $( document.body ).trigger( 'applied_coupon', [ coupon_code ] ); $( document.body ).trigger( 'removed_coupon', [ coupon ] );
Woocommerce Single product page JS events
$( '.wc-tabs-wrapper, .woocommerce-tabs, #rating' ).trigger( 'init' );
Woocommerce Variable product page JS events
$( document.body ).trigger( 'found_variation', [variation] );
Woocommerce Add to cart JS events
$( document.body ).trigger( 'adding_to_cart', [ $thisbutton, data ] ); $( document.body ).trigger( 'added_to_cart', [ response.fragments, response.cart_hash, $thisbutton ] ); $( document.body ).trigger( 'removed_from_cart', [ response.fragments, response.cart_hash, $thisbutton ] ); $( document.body ).trigger( 'wc_cart_button_updated', [ $button ] ); $( document.body ).trigger( 'cart_page_refreshed' ); $( document.body ).trigger( 'cart_totals_refreshed' ); $( document.body ).trigger( 'wc_fragments_loaded' );
Woocommerce Add payment method JS events
$( document.body ).trigger( 'init_add_payment_method' );
To bind listener to these events, use:
jQuery('<event_target>').on('<event_name>', function(){
console.log('<event_name> triggered');
});
F. ex.
jQuery('body').on('init_checkout', function(){
console.log('init_checkout triggered');
// now.do.whatever();
});
Method 2
To find a complete list of all events (and stay updated on any new
ones added) you can consult the .js files in the directory:/wp-content/plugins/woocommerce/assets/js/frontend
Below I report other events (in addition to @jgangso’s answer):
VARIATIONS
hide_variationtriggered when displayed variation data is resetshow_variationtriggered when a variation has been found which matches all attributeswoocommerce_variation_select_changetriggered when an attribute field changeswoocommerce_variation_has_changedtriggered when variation selection has been changedcheck_variationstriggered:- when an attribute field changes
- when reload variation data from the DOM
woocommerce_update_variation_valuestriggered when variations have been updatedwoocommerce_gallery_reset_slide_positionreset the slide position if the variation has a different image than the current onewoocommerce_gallery_init_zoomsets product images for the chosen variation
CART FRAGMENTS
wc_fragments_refreshedtriggered when refreshing of cart fragments via Ajax was successfulwc_fragments_ajax_errortriggered when refreshing of cart fragments via Ajax has failedwc_fragment_refreshrefresh when page is shown after back button (safari)wc_fragments_loadedtriggered after the cart fragments have been loaded
COUNTRY SELECT (CHECKOUT)
country_to_state_changedtriggered when the country changes from the select fieldcountry_to_state_changingandwc_address_i18n_readyhandle locale
SINGLE PRODUCT
wc-product-gallery-before-inittriggered before initializing all the galleries on the pagewc-product-gallery-after-inittriggered after initializing all the galleries on the page
PRICE SLIDER
price_slider_updatedtriggered after price slider updatedprice_slider_createtriggered after price slider createprice_slider_slidetriggered after price slider slideprice_slider_changetriggered after price slider change
Related answers:
- Where to find a complete list of Javascript (JQuery) events that fire on the WooCommerce admin page?
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0