Make sure product is set.
This commit is contained in:
parent
24a5fe7592
commit
365b456fa5
|
@ -24,8 +24,9 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||||
* @param string $operation set, increase and decrease.
|
* @param string $operation set, increase and decrease.
|
||||||
*/
|
*/
|
||||||
function wc_update_product_stock( $product, $stock_quantity = null, $operation = 'set' ) {
|
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() ) {
|
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.
|
// 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();
|
$product_id_with_stock = $product->get_stock_managed_by_id();
|
||||||
|
|
Loading…
Reference in New Issue