Automattic\WooCommerce\Blocks\BlockTypes

ProductStockIndicator::getTextBasedOnStock()protected staticWC 1.0

Get stock text based on stock. For example:

  • In stock
  • Out of stock
  • Available on backorder
  • 2 left in stock

Метод класса: ProductStockIndicator{}

Хуков нет.

Возвращает

Строку. Stock text.

Использование

$result = ProductStockIndicator::getTextBasedOnStock( $is_in_stock, $is_low_stock, $low_stock_amount, $is_on_backorder );
$is_in_stock([bool]) (обязательный)
Whether the product is in stock.
$is_low_stock([bool]) (обязательный)
Whether the product is low in stock.
$low_stock_amount([int|null]) (обязательный)
The amount of stock that is considered low.
$is_on_backorder([bool]) (обязательный)
Whether the product is on backorder.

Код ProductStockIndicator::getTextBasedOnStock() WC 7.3.0

protected static function getTextBasedOnStock( $is_in_stock, $is_low_stock, $low_stock_amount, $is_on_backorder ) {
	if ( $is_low_stock ) {
		return sprintf(
			/* translators: %d is number of items in stock for product */
			__( '%d left in stock', 'woocommerce' ),
			$low_stock_amount
		);
	} elseif ( $is_on_backorder ) {
		return __( 'Available on backorder', 'woocommerce' );
	} elseif ( $is_in_stock ) {
		return __( 'In stock', 'woocommerce' );
	} else {
		return __( 'Out of stock', 'woocommerce' );
	}
}