Grouped product field is being shown on non-grouped product types (#41946)

* Products in this group field should not be visible in any other product types, only visible in the grouped product type.

* Stock status under Inventory tab should not be visible when editing/creating a grouped product.

* Variations tab is not visible when editing/creating a grouped product.

* Add changelog file

* Fix php linter
This commit is contained in:
Maikel David Pérez Gómez 2023-12-08 11:53:40 -03:00 committed by GitHub
parent a91683b9bf
commit cc25c54afd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 16 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Hide Variations tab, stock status and product list for specific product types

View File

@ -126,6 +126,18 @@ class SimpleProductTemplate extends AbstractProductFormTemplate implements Produ
)
);
if ( Features::is_enabled( 'product-variation-management' ) ) {
$variations_hide_conditions = array();
if ( Features::is_enabled( 'product-grouped' ) ) {
$variations_hide_conditions[] = array(
'expression' => 'editedProduct.type === "grouped"',
);
}
if ( Features::is_enabled( 'product-external-affiliate' ) ) {
$variations_hide_conditions[] = array(
'expression' => 'editedProduct.type === "external"',
);
}
$this->add_group(
array(
'id' => $this::GROUP_IDS['VARIATIONS'],
@ -133,11 +145,7 @@ class SimpleProductTemplate extends AbstractProductFormTemplate implements Produ
'attributes' => array(
'title' => __( 'Variations', 'woocommerce' ),
),
'hideConditions' => Features::is_enabled( 'product-external-affiliate' ) ? array(
array(
'expression' => 'editedProduct.type === "external"',
),
) : null,
'hideConditions' => $variations_hide_conditions,
)
);
}
@ -351,12 +359,17 @@ class SimpleProductTemplate extends AbstractProductFormTemplate implements Produ
if ( Features::is_enabled( 'product-grouped' ) ) {
$product_list_section = $general_group->add_section(
array(
'id' => 'product-list-section',
'order' => 35,
'attributes' => array(
'id' => 'product-list-section',
'order' => 35,
'attributes' => array(
'title' => __( 'Products in this group', 'woocommerce' ),
'description' => __( 'Make a collection of related products, enabling customers to purchase multiple items together.', 'woocommerce' ),
),
'hideConditions' => array(
array(
'expression' => 'editedProduct.type !== "grouped"',
),
),
)
);
@ -783,14 +796,19 @@ class SimpleProductTemplate extends AbstractProductFormTemplate implements Produ
);
$product_stock_status_conditional = $product_inventory_section->add_block(
array(
'id' => 'product-stock-status-conditional-wrapper',
'blockName' => 'woocommerce/conditional',
'order' => 20,
'attributes' => array(
'id' => 'product-stock-status-conditional-wrapper',
'blockName' => 'woocommerce/conditional',
'order' => 20,
'attributes' => array(
'mustMatch' => array(
'manage_stock' => array( false ),
),
),
'hideConditions' => Features::is_enabled( 'product-grouped' ) ? array(
array(
'expression' => 'editedProduct.type === "grouped"',
),
) : null,
)
);
$product_stock_status_conditional->add_block(
@ -820,14 +838,19 @@ class SimpleProductTemplate extends AbstractProductFormTemplate implements Produ
);
$product_inventory_advanced = $product_inventory_section->add_block(
array(
'id' => 'product-inventory-advanced',
'blockName' => 'woocommerce/product-collapsible',
'order' => 30,
'attributes' => array(
'id' => 'product-inventory-advanced',
'blockName' => 'woocommerce/product-collapsible',
'order' => 30,
'attributes' => array(
'toggleText' => __( 'Advanced', 'woocommerce' ),
'initialCollapsed' => true,
'persistRender' => true,
),
'hideConditions' => Features::is_enabled( 'product-grouped' ) ? array(
array(
'expression' => 'editedProduct.type === "grouped"',
),
) : null,
)
);
$product_inventory_advanced_wrapper = $product_inventory_advanced->add_block(