diff --git a/includes/wc-stock-functions.php b/includes/wc-stock-functions.php index db122cc2cc2..a5a6f7fbea9 100644 --- a/includes/wc-stock-functions.php +++ b/includes/wc-stock-functions.php @@ -24,8 +24,9 @@ if ( ! defined( 'ABSPATH' ) ) { * @param string $operation set, increase and decrease. */ function wc_update_product_stock( $product, $stock_quantity = null, $operation = 'set' ) { - $product = wc_get_product( $product ); - + if ( ! $product = wc_get_product( $product ) ) { + return false; + } if ( ! is_null( $stock_quantity ) && $product->managing_stock() ) { // Some products (variations) can have their stock managed by their parent. Get the correct ID to reduce here. $product_id_with_stock = $product->get_stock_managed_by_id();