I have a custom WooCommerce product type.
If you switched between the standard WooCommerce type the input are cleared but this does not work for custom types.
So I created a jQuery for this
$('#product-type').on('change', function() {
//do something
});
But this is not the solution because the functions in this code are also running if the page is refreshed.
What can I do to let this work only if the product type is changing
2
Answers
Put your code inside the ready event. The code inside this function fires only when the DOM is completely loaded.
WooCommerce set the product type with JavaScript and is not set wit PHP.
They use the change function if the page is loading and set the right product type on screen.
If you need a function on a specific product type you can do something like this