Automattic\WooCommerce\StoreApi\Schemas\V1
ProductSchema::get_low_stock_remaining()
If a product has low stock, return the remaining stock amount for display.
Метод класса: ProductSchema{}
Хуков нет.
Возвращает
Int|null
.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->get_low_stock_remaining( $product );
- $product(\WC_Product) (обязательный)
- Product instance.
Код ProductSchema::get_low_stock_remaining() ProductSchema::get low stock remaining WC 7.5.1
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; }