Automattic / woocommerce-subscriptions-core

Subscriptions core package for WooCommerce
Other
81 stars 29 forks source link

Enable the "used for variations" checkbox on page load #483

Closed james-allan closed 11 months ago

james-allan commented 11 months ago

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

  1. Make sure you don't have Square active as it triggers JS events that causes this bug to not be reproducible.
  2. Create a variable subscription product using at least 1 attribute
  3. Publish it, everything is good up to this point
  4. Press "Update" button repeatedly without changing anything in the Product data area. (Avoid viewing Attributes or variations tab)
  5. See the issue.

Product impact