Make sure product is set.

This commit is contained in:
Mike Jolley 2017-01-27 16:39:53 +00:00
parent 24a5fe7592
commit 365b456fa5
1 changed files with 3 additions and 2 deletions

View File

@ -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();