This change event runs before our JS is loaded and so we can't rely on this event for our product-type callback to run on.
So, to make sure we enable the "used for variations" checkbox on page load, I've added a $.enableSubscriptionProductFields(); function call to the list of functions that run on page load.
Note: This function is called behind a if ( $( '.options_group.pricing' ).length > 0 ) { condition. I don't know what the historic purpose is of this but it does appear that all product pages have at least .options_group.pricing element so might be a proxy for "is edit product page"? 🤷
How to test this PR
Make sure you don't have Square active as it triggers JS events that causes this bug to not be reproducible.
Create a variable subscription product using at least 1 attribute
Publish it, everything is good up to this point
Press "Update" button repeatedly without changing anything in the Product data area. (Avoid viewing Attributes or variations tab)
See the issue.
Product impact
[x] Added changelog entry (or does not apply)
[ ] Will this PR affect WooCommerce Subscriptions? yes/no/tbc, add issue ref
[ ] Will this PR affect WooCommerce Payments? yes/no/tbc, add issue ref
[ ] Added deprecated functions, hooks or classes to the spreadsheet
Fixes #480
Description
When WC loads the product page the "Used for variations" checkbox is disabled by default.
In WC they then enable this checkbox on page load depending on the product type by triggering a product type dropdown change event. Note the
.trigger( 'change' );
This change event runs before our JS is loaded and so we can't rely on this event for our
product-type
callback to run on.So, to make sure we enable the "used for variations" checkbox on page load, I've added a
$.enableSubscriptionProductFields();
function call to the list of functions that run on page load.Note: This function is called behind a
if ( $( '.options_group.pricing' ).length > 0 ) {
condition. I don't know what the historic purpose is of this but it does appear that all product pages have at least.options_group.pricing
element so might be a proxy for "is edit product page"? 🤷How to test this PR
Product impact