Automattic\WooCommerce\StoreApi\Schemas\V1
ProductSchema::get_low_stock_remaining()
If a product has low stock, return the remaining stock amount for display.
Method of the class: ProductSchema{}
No Hooks.
Return
Int|null
.
Usage
// protected - for code of main (parent) or child class $result = $this->get_low_stock_remaining( $product );
- $product(\WC_Product) (required)
- Product instance.
ProductSchema::get_low_stock_remaining() ProductSchema::get low stock remaining code WC 9.4.2
protected function get_low_stock_remaining( \WC_Product $product ) { $remaining_stock = $this->get_remaining_stock( $product ); $stock_format = get_option( 'woocommerce_stock_format' ); // Don't show the low stock badge if the settings doesn't allow it. if ( 'no_amount' === $stock_format ) { return null; } // Show the low stock badge if the remaining stock is below or equal to the threshold. if ( ! is_null( $remaining_stock ) && $remaining_stock <= wc_get_low_stock_amount( $product ) ) { return max( $remaining_stock, 0 ); } return null; }