Automattic\WooCommerce\StoreApi\Utilities
CartController::add_product_names_to_message
Generates the error message for out of stock products and adds product names to it.
Method of the class: CartController{}
No Hooks.
Returns
null. Nothing (null).
Usage
// private - for code of main (parent) class only $result = $this->add_product_names_to_message( $singular, $plural, $items );
- $singular(string) (required)
- The message to use when only one product is in the list.
- $plural(string) (required)
- The message to use when more than one product is in the list.
- $items(array) (required)
- The list of cart items whose names should be inserted into the message.
CartController::add_product_names_to_message() CartController::add product names to message code WC 10.3.5
private function add_product_names_to_message( $singular, $plural, $items ) {
$product_names = wc_list_pluck( $items, 'getProductName' );
$message = ( count( $items ) > 1 ) ? $plural : $singular;
return sprintf(
$message,
ArrayUtils::natural_language_join( $product_names, true )
);
}