WordPress at Your Fingertips
function is not described

Automattic\WooCommerce\Blocks\StoreApi\Utilities

CartController::get_error_message_for_stock_exception_type() private WC 1.0

Takes a string describing the type of stock extension, whether there is a single product or multiple products causing this exception and returns an appropriate error message.

{} It's a method of the class: CartController{}

No Hooks.

Return

String.

Usage

// private - for code of main (parent) class only
$result = $this->get_error_message_for_stock_exception_type( $exception_type, $singular_or_plural );
$exception_type(string) (required)
The type of exception encountered.
$singular_or_plural(string) (required)
Whether to get the error message for a single product or multiple.

Code of CartController::get_error_message_for_stock_exception_type() WC 5.7.0

private function get_error_message_for_stock_exception_type( $exception_type, $singular_or_plural ) {
	$stock_error_messages = [
		'out_of_stock'         => [
			/* translators: %s: product name. */
			'singular' => __(
				'%s is out of stock and cannot be purchased. Please remove it from your cart.',
				'woocommerce'
			),
			/* translators: %s: product names. */
			'plural'   => __(
				'%s are out of stock and cannot be purchased. Please remove them from your cart.',
				'woocommerce'
			),
		],
		'not_purchasable'      => [
			/* translators: %s: product name. */
			'singular' => __(
				'%s cannot be purchased. Please remove it from your cart.',
				'woocommerce'
			),
			/* translators: %s: product names. */
			'plural'   => __(
				'%s cannot be purchased. Please remove them from your cart.',
				'woocommerce'
			),
		],
		'too_many_in_cart'     => [
			/* translators: %s: product names. */
			'singular' => __(
				'There are too many %s in the cart. Only 1 can be purchased. Please reduce the quantity in your cart.',
				'woocommerce'
			),
			/* translators: %s: product names. */
			'plural'   => __(
				'There are too many %s in the cart. Only 1 of each can be purchased. Please reduce the quantities in your cart.',
				'woocommerce'
			),
		],
		'partial_out_of_stock' => [
			/* translators: %s: product names. */
			'singular' => __(
				'There is not enough %s in stock. Please reduce the quantity in your cart.',
				'woocommerce'
			),
			/* translators: %s: product names. */
			'plural'   => __(
				'There are not enough %s in stock. Please reduce the quantities in your cart.',
				'woocommerce'
			),
		],
	];

	if (
		isset( $stock_error_messages[ $exception_type ] ) &&
		isset( $stock_error_messages[ $exception_type ][ $singular_or_plural ] )
	) {
		return $stock_error_messages[ $exception_type ][ $singular_or_plural ];
	}

	return __( 'There was an error with an item in your cart.', 'woocommerce' );
}