-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Control the show or hide of the product data tab and meta box added t…
…o the product editing page by JS.
- Loading branch information
Showing
4 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,44 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import $ from 'jquery'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
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 ); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters