Show `Stock status` options as radio buttons (#37278)
* Add check to show Stock status as radiobuttons * Add changelog * Fix lint * Fix typo * Fix flaky e2e tests * Rename hook * Fix validation to show radio --------- Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com>
This commit is contained in:
parent
748677c4a1
commit
d0450fa43c
|
@ -0,0 +1,4 @@
|
|||
Significance: minor
|
||||
Type: dev
|
||||
|
||||
Show "Stock status" as a collection of radio buttons
|
|
@ -115,18 +115,33 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
|
||||
}
|
||||
|
||||
woocommerce_wp_select(
|
||||
array(
|
||||
'id' => '_stock_status',
|
||||
'value' => $product_object->get_stock_status( 'edit' ),
|
||||
'wrapper_class' => 'stock_status_field hide_if_variable hide_if_external hide_if_grouped',
|
||||
'label' => __( 'Stock status', 'woocommerce' ),
|
||||
'options' => wc_get_product_stock_status_options(),
|
||||
'desc_tip' => true,
|
||||
'description' => __( 'Controls whether or not the product is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce' ),
|
||||
)
|
||||
$stock_status_options = wc_get_product_stock_status_options();
|
||||
$stock_status_count = count( $stock_status_options );
|
||||
$common_stock_status_args = array(
|
||||
'id' => '_stock_status',
|
||||
'value' => $product_object->get_stock_status( 'edit' ),
|
||||
'wrapper_class' => 'stock_status_field hide_if_variable hide_if_external hide_if_grouped',
|
||||
'label' => __( 'Stock status', 'woocommerce' ),
|
||||
'options' => $stock_status_options,
|
||||
);
|
||||
|
||||
/**
|
||||
* Allow 3rd parties to control whether the "Stock status" option will use radio buttons or a select.
|
||||
*
|
||||
* @since 7.6.0
|
||||
*
|
||||
* @param bool If false, the "Stock status" will be shown as a select. Default: it will use radio buttons.
|
||||
*/
|
||||
if ( apply_filters( 'woocommerce_product_stock_status_use_radio', $stock_status_count <= 3 && $stock_status_count >= 1 ) ) {
|
||||
woocommerce_wp_radio( $common_stock_status_args );
|
||||
} else {
|
||||
$select_input_args = array(
|
||||
'desc_tip' => true,
|
||||
'description' => __( 'Controls whether or not the product is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce' ),
|
||||
);
|
||||
woocommerce_wp_select( array_merge( $common_stock_status_args, $select_input_args ) );
|
||||
}
|
||||
|
||||
do_action( 'woocommerce_product_options_stock_status' );
|
||||
?>
|
||||
</div>
|
||||
|
|
|
@ -55,10 +55,10 @@ test.describe.serial( 'Add New Variable Product Page', () => {
|
|||
if ( i > 0 ) {
|
||||
await page.click( 'button.add_attribute' );
|
||||
}
|
||||
await page.fill(
|
||||
`input[name="attribute_names[${ i }]"]`,
|
||||
`attr #${ i + 1 }`
|
||||
);
|
||||
const input = `input[name="attribute_names[${ i }]"]`;
|
||||
|
||||
await page.waitForSelector( input, { timeout: 1000 } ); // Wait for up to 1 second
|
||||
await page.fill( input, `attr #${ i + 1 }` );
|
||||
await page.fill(
|
||||
`textarea[name="attribute_values[${ i }]"]`,
|
||||
'val1 | val2'
|
||||
|
@ -67,6 +67,7 @@ test.describe.serial( 'Add New Variable Product Page', () => {
|
|||
await page.keyboard.press( 'ArrowUp' );
|
||||
await page.click( 'text=Save attributes' );
|
||||
|
||||
await page.waitForTimeout( 1000 ); // Wait for 1 second
|
||||
// Save before going to the Variations tab to prevent variations from all attributes to be automatically created
|
||||
await page.locator( '#save-post' ).click();
|
||||
await expect(
|
||||
|
@ -205,10 +206,10 @@ test.describe.serial( 'Add New Variable Product Page', () => {
|
|||
if ( i > 0 ) {
|
||||
await page.click( 'button.add_attribute' );
|
||||
}
|
||||
await page.fill(
|
||||
`input[name="attribute_names[${ i }]"]`,
|
||||
`attr #${ i + 1 }`
|
||||
);
|
||||
const input = `input[name="attribute_names[${ i }]"]`;
|
||||
|
||||
await page.waitForSelector( input, { timeout: 1000 } ); // Wait for up to 1 seconds
|
||||
await page.fill( input, `attr #${ i + 1 }` );
|
||||
await page.fill(
|
||||
`textarea[name="attribute_values[${ i }]"]`,
|
||||
'val1 | val2'
|
||||
|
@ -222,6 +223,7 @@ test.describe.serial( 'Add New Variable Product Page', () => {
|
|||
).toBeVisible();
|
||||
}
|
||||
|
||||
await page.waitForTimeout( 1000 ); // Wait for 1 second
|
||||
// Save before going to the Variations tab to prevent variations from all attributes to be automatically created
|
||||
await page.locator( '#save-post' ).click();
|
||||
await expect(
|
||||
|
|
Loading…
Reference in New Issue