wc_get_low_stock_amount()WC 3.5.0

Return low stock amount to determine if notification needs to be sent

Since 5.2.0, this function no longer redirects from variation to its parent product. Low stock amount can now be attached to the variation itself and if it isn't, only then we check the parent product, and if it's not there, then we take the default from the store-wide setting.

No Hooks.

Return

Int.

Usage

wc_get_low_stock_amount( $product );
$product(WC_Product) (required)
Product to get data from.

Changelog

Since 3.5.0 Introduced.

wc_get_low_stock_amount() code WC 8.6.1

function wc_get_low_stock_amount( WC_Product $product ) {
	$low_stock_amount = $product->get_low_stock_amount();

	if ( '' === $low_stock_amount && $product->is_type( 'variation' ) ) {
		$product          = wc_get_product( $product->get_parent_id() );
		$low_stock_amount = $product->get_low_stock_amount();
	}

	if ( '' === $low_stock_amount ) {
		$low_stock_amount = get_option( 'woocommerce_notify_low_stock_amount', 2 );
	}

	return (int) $low_stock_amount;
}