Skip to content
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

Convert "Allow backorders?" into radio buttons #37282

Merged
merged 6 commits into from Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,4 @@
Significance: minor
Type: dev

Convert "Allow backorders?" into radio buttons
@@ -1,4 +1,4 @@
<?php

Check notice on line 1 in plugins/woocommerce/includes/admin/meta-boxes/views/html-product-data-inventory.php

View workflow job for this annotation

GitHub Actions / Check pull request changes to highlight

new filter found - woocommerce_product_allow_backorder_use_radio

\'woocommerce_product_allow_backorder_use_radio\' introduced in 7.6.0
/**
* Displays the inventory tab in the product data meta box.
*
Expand Down Expand Up @@ -64,17 +64,28 @@

echo '<input type="hidden" name="_original_stock" value="' . esc_attr( wc_stock_amount( $product_object->get_stock_quantity( 'edit' ) ) ) . '" />';

woocommerce_wp_select(
array(
'id' => '_backorders',
'value' => $product_object->get_backorders( 'edit' ),
'label' => __( 'Allow backorders?', 'woocommerce' ),
'options' => wc_get_product_backorder_options(),
'desc_tip' => true,
'description' => __( 'If managing stock, this controls whether or not backorders are allowed. If enabled, stock quantity can go below 0.', 'woocommerce' ),
)
$backorder_args = array(
'id' => '_backorders',
'value' => $product_object->get_backorders( 'edit' ),
'label' => __( 'Allow backorders?', 'woocommerce' ),
'options' => wc_get_product_backorder_options(),
'desc_tip' => true,
'description' => __( 'If managing stock, this controls whether or not backorders are allowed. If enabled, stock quantity can go below 0.', 'woocommerce' ),
);

/**
* Allow 3rd parties to control whether "Allow backorder?" option will use radio buttons or a select.
*
* @since 7.6.0
*
* @param bool If false, "Allow backorders?" will be shown as a select. Default: it will use radio buttons.
*/
if ( apply_filters( 'woocommerce_product_allow_backorder_use_radio', true ) ) {
woocommerce_wp_radio( $backorder_args );
} else {
woocommerce_wp_select( $backorder_args );
}

woocommerce_wp_text_input(
array(
'id' => '_low_stock_amount',
Expand Down Expand Up @@ -115,14 +126,16 @@

}

$stock_status_options = wc_get_product_stock_status_options();
$stock_status_count = count( $stock_status_options );
$common_stock_status_args = array(
$stock_status_options = wc_get_product_stock_status_options();
$stock_status_count = count( $stock_status_options );
$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,
'desc_tip' => true,
'description' => __( 'Controls whether or not the product is listed as "in stock" or "out of stock" on the frontend.', 'woocommerce' ),
Comment on lines +129 to +138
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes are not directly related to the PR. It would be good in the future to either split them out or, since this is admittedly a small change and closely related, just reference that the change was made in the PR description/comments, so it is clear to the reviewer!

);

/**
Expand All @@ -133,13 +146,9 @@
* @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 );
woocommerce_wp_radio( $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 ) );
woocommerce_wp_select( $stock_status_args );
}

do_action( 'woocommerce_product_options_stock_status' );
Expand Down