I'm using Woocommerce (Wordpress) and utilizing the custom event listener defined by woocommerce called show_variation
to listen for changes in the variation shown (when changed from viewing one variation of a product to another).
Question 1
The problem with this event listener is that it fires on page load, and I need it to only fire on changes (after page load). As I'm not sure whether this could load after the jQuery $(window).on('load', function(){...
I'm reluctant to placing my faith entirely on the on(load)
event. Also I would prefer it to only be fired .on('click')
.
Therefore my question is: is it possible to require a double event for the function to be fired? I'm thinking something like beneath (doesn't work though):
$(element).on('click + show_variation', function(){
alert("variation shown");
});
As of now I've "solved" this by doing wrapping the show_variation
event listener inside a click
event listener, but I'm afraid that this isn't a bulletproof solution:
$(container).on('click', function(){
$(element).on('show_variation', function(){
alert("variation shown");
});
});
However, using te last solution causes the show_variation
event listener to bubble (adding multiple event listeners and firing multiple functions).