After Variations are created, disable the fields that don’t do anything (#45838)
* Disable woocommerce/product-regular-price-field when product type is variable * Disable woocommerce/product-sale-price-field when product type is variable * Disable woocommerce/product-sku-field when product type is variable * Disable Track stock quantity toggle when product type is variable * Disable woocommerce/product-radio-field when product type is variable * Disable woocommerce/product-shipping-class-field when product type is variable * Disable woocommerce/product-shipping-dimensions-fields when product type is variable * Add changelog files * Fix php linter
This commit is contained in:
parent
27124828e9
commit
54476cb7f3
|
@ -0,0 +1,4 @@
|
|||
Significance: minor
|
||||
Type: add
|
||||
|
||||
Disable the fields that are not required in variable products because they are set in each variation
|
|
@ -16,7 +16,6 @@ Radio button field for the product editor.
|
|||
- **Type:** `String`
|
||||
- **Required:** `No`
|
||||
|
||||
|
||||
### property
|
||||
|
||||
- **Type:** `String`
|
||||
|
@ -27,6 +26,11 @@ Radio button field for the product editor.
|
|||
- **Type:** `Array`
|
||||
- **Required:** `Yes`
|
||||
|
||||
### disabled
|
||||
|
||||
- **Type:** `Boolean`
|
||||
- **Required:** `No`
|
||||
|
||||
## Usage
|
||||
|
||||
Here's an example of the usage on the "Charge sales tax on" field in the Pricing section:
|
||||
|
|
|
@ -24,6 +24,10 @@
|
|||
},
|
||||
"default": [],
|
||||
"__experimentalRole": "content"
|
||||
},
|
||||
"disabled": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
}
|
||||
},
|
||||
"supports": {
|
||||
|
|
|
@ -17,7 +17,7 @@ export function Edit( {
|
|||
context: { postType },
|
||||
}: ProductEditorBlockEditProps< RadioBlockAttributes > ) {
|
||||
const blockProps = useWooBlockProps( attributes );
|
||||
const { description, options, property, title } = attributes;
|
||||
const { description, options, property, title, disabled } = attributes;
|
||||
const [ value, setValue ] = useProductEntityProp< string >( property, {
|
||||
postType,
|
||||
fallbackValue: '',
|
||||
|
@ -31,6 +31,7 @@ export function Edit( {
|
|||
selected={ value }
|
||||
options={ options }
|
||||
onChange={ ( selected ) => setValue( selected || '' ) }
|
||||
disabled={ disabled }
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
|
|
@ -8,4 +8,5 @@ export interface RadioBlockAttributes extends BlockAttributes {
|
|||
description: string;
|
||||
property: string;
|
||||
options: [];
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,10 @@
|
|||
"name": {
|
||||
"type": "string",
|
||||
"__experimentalRole": "content"
|
||||
},
|
||||
"disabled": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
}
|
||||
},
|
||||
"supports": {
|
||||
|
|
|
@ -57,6 +57,7 @@ export function Edit( {
|
|||
name={ 'woocommerce-product-sku' }
|
||||
onChange={ setSku }
|
||||
value={ sku || '' }
|
||||
disabled={ attributes.disabled }
|
||||
/>
|
||||
</BaseControl>
|
||||
</div>
|
||||
|
|
|
@ -21,6 +21,10 @@
|
|||
},
|
||||
"tooltip": {
|
||||
"type": "string"
|
||||
},
|
||||
"disabled": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
}
|
||||
},
|
||||
"supports": {
|
||||
|
|
|
@ -30,7 +30,7 @@ export function Edit( {
|
|||
context,
|
||||
}: ProductEditorBlockEditProps< SalePriceBlockAttributes > ) {
|
||||
const blockProps = useWooBlockProps( attributes );
|
||||
const { label, help, isRequired, tooltip } = attributes;
|
||||
const { label, help, isRequired, tooltip, disabled } = attributes;
|
||||
const [ regularPrice, setRegularPrice ] = useEntityProp< string >(
|
||||
'postType',
|
||||
context.postType || 'product',
|
||||
|
@ -120,6 +120,7 @@ export function Edit( {
|
|||
label
|
||||
)
|
||||
}
|
||||
disabled={ disabled }
|
||||
onBlur={ validateRegularPrice }
|
||||
/>
|
||||
</BaseControl>
|
||||
|
|
|
@ -7,4 +7,5 @@ export interface SalePriceBlockAttributes extends BlockAttributes {
|
|||
label: string;
|
||||
help?: string;
|
||||
isRequired?: boolean;
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,10 @@
|
|||
},
|
||||
"tooltip": {
|
||||
"type": "string"
|
||||
},
|
||||
"disabled": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
}
|
||||
},
|
||||
"supports": {
|
||||
|
|
|
@ -29,7 +29,7 @@ export function Edit( {
|
|||
context,
|
||||
}: ProductEditorBlockEditProps< SalePriceBlockAttributes > ) {
|
||||
const blockProps = useWooBlockProps( attributes );
|
||||
const { label, help, tooltip } = attributes;
|
||||
const { label, help, tooltip, disabled } = attributes;
|
||||
const [ regularPrice ] = useEntityProp< string >(
|
||||
'postType',
|
||||
context.postType || 'product',
|
||||
|
@ -102,6 +102,7 @@ export function Edit( {
|
|||
label
|
||||
)
|
||||
}
|
||||
disabled={ disabled }
|
||||
onBlur={ validateSalePrice }
|
||||
/>
|
||||
</BaseControl>
|
||||
|
|
|
@ -6,4 +6,5 @@ import { BlockAttributes } from '@wordpress/blocks';
|
|||
export interface SalePriceBlockAttributes extends BlockAttributes {
|
||||
label: string;
|
||||
help?: string;
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,10 @@
|
|||
"title": {
|
||||
"type": "string",
|
||||
"__experimentalRole": "content"
|
||||
},
|
||||
"disabled": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
}
|
||||
},
|
||||
"supports": {
|
||||
|
|
|
@ -161,7 +161,7 @@ export function Edit( {
|
|||
shippingClasses ?? []
|
||||
),
|
||||
] }
|
||||
disabled={ virtual }
|
||||
disabled={ attributes.disabled || virtual }
|
||||
help={ createInterpolateElement(
|
||||
__(
|
||||
'Manage shipping classes and rates in <Link>global settings</Link>.',
|
||||
|
|
|
@ -5,4 +5,5 @@ import { BlockAttributes } from '@wordpress/blocks';
|
|||
|
||||
export interface ShippingClassBlockAttributes extends BlockAttributes {
|
||||
title: string;
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
|
|
@ -11,6 +11,10 @@
|
|||
"__contentEditable": {
|
||||
"type": "string",
|
||||
"__experimentalRole": "content"
|
||||
},
|
||||
"disabled": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
}
|
||||
},
|
||||
"supports": {
|
||||
|
|
|
@ -90,7 +90,7 @@ export function Edit( {
|
|||
onFocus: () => setHighlightSide( side ),
|
||||
onBlur: () => setHighlightSide( undefined ),
|
||||
suffix: dimensionUnit,
|
||||
disabled: virtual,
|
||||
disabled: attributes.disabled || virtual,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -185,7 +185,7 @@ export function Edit( {
|
|||
suffix: weightUnit,
|
||||
ref: weightRef,
|
||||
onBlur: validateWeight,
|
||||
disabled: virtual,
|
||||
disabled: attributes.disabled || virtual,
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
|
@ -5,4 +5,5 @@ import { BlockAttributes } from '@wordpress/blocks';
|
|||
|
||||
export interface ShippingDimensionsBlockAttributes extends BlockAttributes {
|
||||
__contentEditable: string;
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
|
|
@ -6,4 +6,5 @@ import { RadioControl } from '@wordpress/components';
|
|||
export type RadioFieldProps< T > = Omit< RadioControl.Props< T >, 'label' > & {
|
||||
title: string;
|
||||
description?: string;
|
||||
disabled?: boolean;
|
||||
};
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
Significance: minor
|
||||
Type: add
|
||||
|
||||
Disable the fields that are not required in variable products because they are set in each variation
|
|
@ -623,6 +623,11 @@ class SimpleProductTemplate extends AbstractProductFormTemplate implements Produ
|
|||
'</a>'
|
||||
),
|
||||
),
|
||||
'disableConditions' => array(
|
||||
array(
|
||||
'expression' => 'editedProduct.type === "variable"',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
$pricing_column_2 = $pricing_columns->add_block(
|
||||
|
@ -643,6 +648,11 @@ class SimpleProductTemplate extends AbstractProductFormTemplate implements Produ
|
|||
'attributes' => array(
|
||||
'label' => __( 'Sale price', 'woocommerce' ),
|
||||
),
|
||||
'disableConditions' => array(
|
||||
array(
|
||||
'expression' => 'editedProduct.type === "variable"',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
$product_pricing_section->add_block(
|
||||
|
@ -791,8 +801,15 @@ class SimpleProductTemplate extends AbstractProductFormTemplate implements Produ
|
|||
'id' => 'product-sku-field',
|
||||
'blockName' => 'woocommerce/product-sku-field',
|
||||
'order' => 10,
|
||||
'disableConditions' => array(
|
||||
array(
|
||||
'expression' => 'editedProduct.type === "variable"',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$manage_stock = 'yes' === get_option( 'woocommerce_manage_stock' );
|
||||
$product_inventory_inner_section->add_block(
|
||||
array(
|
||||
'id' => 'product-track-stock',
|
||||
|
@ -801,19 +818,24 @@ class SimpleProductTemplate extends AbstractProductFormTemplate implements Produ
|
|||
'attributes' => array(
|
||||
'label' => __( 'Track inventory', 'woocommerce' ),
|
||||
'property' => 'manage_stock',
|
||||
'disabled' => 'yes' !== get_option( 'woocommerce_manage_stock' ),
|
||||
'disabledCopy' => sprintf(
|
||||
'disabled' => ! $manage_stock,
|
||||
'disabledCopy' => ! $manage_stock ? sprintf(
|
||||
/* translators: %1$s: Learn more link opening tag. %2$s: Learn more link closing tag.*/
|
||||
__( 'Per your %1$sstore settings%2$s, inventory management is <strong>disabled</strong>.', 'woocommerce' ),
|
||||
'<a href="' . admin_url( 'admin.php?page=wc-settings&tab=products§ion=inventory' ) . '" target="_blank" rel="noreferrer">',
|
||||
'</a>'
|
||||
),
|
||||
) : null,
|
||||
),
|
||||
'hideConditions' => Features::is_enabled( 'product-external-affiliate' ) || Features::is_enabled( 'product-grouped' ) ? array(
|
||||
array(
|
||||
'expression' => 'editedProduct.type === "external" || editedProduct.type === "grouped"',
|
||||
),
|
||||
) : null,
|
||||
'disableConditions' => array(
|
||||
array(
|
||||
'expression' => 'editedProduct.type === "variable"',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
$product_inventory_quantity_hide_conditions = array(
|
||||
|
@ -868,6 +890,11 @@ class SimpleProductTemplate extends AbstractProductFormTemplate implements Produ
|
|||
),
|
||||
),
|
||||
'hideConditions' => $product_stock_status_hide_conditions,
|
||||
'disableConditions' => array(
|
||||
array(
|
||||
'expression' => 'editedProduct.type === "variable"',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -1045,6 +1072,11 @@ class SimpleProductTemplate extends AbstractProductFormTemplate implements Produ
|
|||
'id' => 'product-shipping-class',
|
||||
'blockName' => 'woocommerce/product-shipping-class-field',
|
||||
'order' => 10,
|
||||
'disableConditions' => array(
|
||||
array(
|
||||
'expression' => 'editedProduct.type === "variable"',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
$product_fee_and_dimensions_section->add_block(
|
||||
|
@ -1052,6 +1084,11 @@ class SimpleProductTemplate extends AbstractProductFormTemplate implements Produ
|
|||
'id' => 'product-shipping-dimensions',
|
||||
'blockName' => 'woocommerce/product-shipping-dimensions-fields',
|
||||
'order' => 20,
|
||||
'disableConditions' => array(
|
||||
array(
|
||||
'expression' => 'editedProduct.type === "variable"',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -91,7 +91,7 @@ test( 'can update stock status', async ( { page, product } ) => {
|
|||
|
||||
test( 'can track stock quantity', async ( { page, product } ) => {
|
||||
await test.step( 'enable track stock quantity', async () => {
|
||||
await page.getByLabel( 'Track stock quantity for this' ).check();
|
||||
await page.getByLabel( 'Track inventory' ).check();
|
||||
// await closeTourModal( { page, timeout: 2000 } );
|
||||
await page.getByRole( 'button', { name: 'Advanced' } ).click();
|
||||
await page.getByLabel( "Don't allow purchases" ).check();
|
||||
|
|
Loading…
Reference in New Issue