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

Method of the class: ProductStockIndicator{}

No Hooks.

Return

String. Stock text.

Usage

$result = ProductStockIndicator::getTextBasedOnStock( $is_in_stock, $is_low_stock, $low_stock_amount, $is_on_backorder );
$is_in_stock(true|false) (required)
Whether the product is in stock.
$is_low_stock(true|false) (required)
Whether the product is low in stock.
$low_stock_amount(int|null) (required)
The amount of stock that is considered low.
$is_on_backorder(true|false) (required)
Whether the product is on backorder.

ProductStockIndicator::getTextBasedOnStock() code WC 9.4.2

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' );
	}
}