-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WooCommerce Subscriptions compatibility: Fix the visible issue of the product data tab and meta box for some unsupported product types #2087
Changes from 3 commits
d376e01
f325aa1
841cb94
d013eaa
d13cdf6
0468a73
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
["@woocommerce/components","@woocommerce/currency","@woocommerce/customer-effort-score","@woocommerce/data","@woocommerce/date","@woocommerce/navigation","@woocommerce/number","@woocommerce/settings","@woocommerce/tracks","@wordpress/api-fetch","@wordpress/components","@wordpress/compose","@wordpress/data","@wordpress/data-controls","@wordpress/date","@wordpress/dom","@wordpress/element","@wordpress/hooks","@wordpress/html-entities","@wordpress/i18n","@wordpress/primitives","@wordpress/url","lodash","react","react-dom"] | ||
["@woocommerce/components","@woocommerce/currency","@woocommerce/customer-effort-score","@woocommerce/data","@woocommerce/date","@woocommerce/navigation","@woocommerce/number","@woocommerce/settings","@woocommerce/tracks","@wordpress/api-fetch","@wordpress/components","@wordpress/compose","@wordpress/data","@wordpress/data-controls","@wordpress/date","@wordpress/dom","@wordpress/element","@wordpress/hooks","@wordpress/html-entities","@wordpress/i18n","@wordpress/primitives","@wordpress/url","jquery","lodash","react","react-dom"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,45 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import $ from 'jquery'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import './custom-inputs'; | ||
import './index.scss'; | ||
|
||
const applicableProductTypes = new Set( [ | ||
// Simple product | ||
'simple', | ||
// Variable product | ||
'variable', | ||
// Product bundle from WooCommerce Product Bundles | ||
'bundle', | ||
] ); | ||
|
||
// Originally, this extension relied on a WooCommerce core processing to show or hide | ||
// the product data tab and meta box added to the product editing page. | ||
// | ||
// However, WooCommerce Subscriptions has an additional processing, which overrides | ||
// the associated processed result in WooCommerce core. | ||
// | ||
// Since there is no available way to continue to work around it with `show_if_{productType}` | ||
// or `hide_if_{productType}` CSS classes, a jQuery custom event dispatched by WooCommerce core | ||
// is used to handle show or hide them instead. | ||
// | ||
// See: | ||
// - https://github.com/woocommerce/google-listings-and-ads/issues/2086 | ||
// | ||
// Ref: | ||
// - https://github.com/woocommerce/woocommerce/blob/8.0.3/plugins/woocommerce/client/legacy/js/admin/meta-boxes-product.js#L204-L243 | ||
// - https://github.com/Automattic/woocommerce-subscriptions-core/blob/6.2.0/assets/js/admin/admin.js#L18-L88 | ||
// - https://github.com/woocommerce/woocommerce/blob/8.0.3/plugins/woocommerce/client/legacy/js/admin/meta-boxes-product.js#L130-L158 | ||
$( document ).on( | ||
'woocommerce-product-type-change', | ||
'body', | ||
( e, productType ) => { | ||
const shouldDisplay = applicableProductTypes.has( productType ); | ||
$( '.gla_attributes_tab, .gla_meta_box' ).toggle( shouldDisplay ); | ||
} | ||
); |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This integration class doesn't actually participate in any runtime processing anymore now, but I'm not sure if it would be better to remove it entirely. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What would be the downside of removing the file entirely? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Originally I guess it might be ok to keep it as a reminder that this extension doesn't support the product types of WooCommerce Subscriptions. After second thoughts, I think it should be fine to remove it because the current way only uses an inclusive list of the supported product types. Other product types will naturally not be supported. Removed in d013eaa |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just have one additional comment about this list. Previously we had the PHP filter
woocommerce_gla_supported_product_types
which allows an integration such as Bundles to add themselves to the list. We added this filter not only for the internal integrations we support, but also if there is a plugin which wants to add support for syncing their "specific" product type. With this list it's not possible to extend the supported product types. Can we pass this list dynamically to the JS so it's run through thewoocommerce_gla_supported_product_types
filter?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion!
Since the original execution order of the related processing is:
On the first call, the inline script
glaData
is created along with the script file registration. However, the third call has not yet been made, which results in the supported product types not containing the'bundle'
.Therefore, I adjusted the execution order as follows in d13cdf6, so that the script registration will be called after the
IntegrationInitializer->register
.AssetsHandler->add_many
andAssetsHandler->register
And removed the former calls of
AssetsHandler->add_many
andAssetsHandler->register
.