Fix "Out of stock threshold" when filed value is empty - Fix/issue 36960 (#37855)

This commit is contained in:
Jorge A. Torres 2023-04-25 15:36:43 -03:00 committed by GitHub
commit 226af5017d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 3 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Above notification threshold when "Out of stock threshold" filed value is empty

View File

@ -1386,7 +1386,7 @@ class WC_Product extends WC_Abstract_Legacy_Product {
return;
}
$stock_is_above_notification_threshold = ( $this->get_stock_quantity() > get_option( 'woocommerce_notify_no_stock_amount', 0 ) );
$stock_is_above_notification_threshold = ( (int) $this->get_stock_quantity() > absint( get_option( 'woocommerce_notify_no_stock_amount', 0 ) ) );
$backorders_are_allowed = ( 'no' !== $this->get_backorders() );
if ( $stock_is_above_notification_threshold ) {

View File

@ -38,6 +38,8 @@ class OptionSanitizer {
2
);
}
// Cast "Out of stock threshold" field to absolute integer to prevent storing empty value.
self::add_filter( 'woocommerce_admin_settings_sanitize_option_woocommerce_notify_no_stock_amount', 'absint' );
}
/**

View File

@ -66,7 +66,7 @@ class WC_Tests_Product extends WC_Unit_Test_Case {
* [3, 4, false, "outofstock"]
*
* @param int $stock_quantity Current stock quantity for the product.
* @param bool $notify_no_stock_amount Value for the woocommerce_notify_no_stock_amount option.
* @param int $notify_no_stock_amount Value for the woocommerce_notify_no_stock_amount option.
* @param bool $accepts_backorders Whether the product accepts backorders or not.
* @param string $expected_stock_status The expected stock status of the product after being saved.
*/

View File

@ -154,7 +154,7 @@ class WC_Tests_Product_Variable extends WC_Unit_Test_Case {
* [3, 4, false, "outofstock"]
*
* @param int $stock_quantity Current stock quantity for the product.
* @param bool $notify_no_stock_amount Value for the woocommerce_notify_no_stock_amount option.
* @param int $notify_no_stock_amount Value for the woocommerce_notify_no_stock_amount option.
* @param bool $accepts_backorders Whether the product accepts backorders or not.
* @param string $expected_stock_status The expected stock status of the product after being saved.
*/