Automattic\WooCommerce\StoreApi\Utilities
CartController::get_error_message_for_stock_exception_type
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.
Метод класса: CartController{}
Хуков нет.
Возвращает
Строку.
Использование
// private - только в коде основоного (родительского) класса $result = $this->get_error_message_for_stock_exception_type( $exception_type, $singular_or_plural );
- $exception_type(строка) (обязательный)
- The type of exception encountered.
- $singular_or_plural(строка) (обязательный)
- Whether to get the error message for a single product or multiple.
Код CartController::get_error_message_for_stock_exception_type() CartController::get error message for stock exception type WC 10.5.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' => esc_html__(
'%s is out of stock and cannot be purchased. Please remove it from your cart.',
'woocommerce'
),
/* translators: %s: product names. */
'plural' => esc_html__(
'%s are out of stock and cannot be purchased. Please remove them from your cart.',
'woocommerce'
),
],
'not_purchasable' => [
/* translators: %s: product name. */
'singular' => esc_html__(
'%s cannot be purchased. Please remove it from your cart.',
'woocommerce'
),
/* translators: %s: product names. */
'plural' => esc_html__(
'%s cannot be purchased. Please remove them from your cart.',
'woocommerce'
),
],
'too_many_in_cart' => [
/* translators: %s: product names. */
'singular' => esc_html__(
'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' => esc_html__(
'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' => esc_html__(
'There is not enough %s in stock. Please reduce the quantity in your cart.',
'woocommerce'
),
/* translators: %s: product names. */
'plural' => esc_html__(
'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 esc_html__( 'There was an error with an item in your cart.', 'woocommerce' );
}