Automattic\WooCommerce\Internal\PushNotifications\Notifications
StockNotification::build_message
Builds the message payload for the notification.
Method of the class: StockNotification{}
No Hooks.
Returns
Array{format:. string, args: string[]}
Usage
// private - for code of main (parent) class only $result = $this->build_message( $product_name, $site_title, $product ): array;
- $product_name(string) (required)
- The sanitized product name.
- $site_title(string) (required)
- The sanitized site title.
- $product(WC_Product) (required)
- The product object (used as a fallback when no trigger-time stock was captured).
StockNotification::build_message() StockNotification::build message code WC 10.9.1
private function build_message( string $product_name, string $site_title, WC_Product $product ): array {
switch ( $this->event_type ) {
case self::EVENT_OUT_OF_STOCK:
return array(
'format' => '%1$s is out of stock on %2$s',
'args' => array( $product_name, $site_title ),
);
case self::EVENT_ON_BACKORDER:
return array(
'format' => '%1$s has been backordered on %2$s',
'args' => array( $product_name, $site_title ),
);
default:
$stock = null !== $this->stock_quantity_at_trigger
? $this->stock_quantity_at_trigger
: $product->get_stock_quantity();
return array(
'format' => '%1$s is running low (%2$s remaining) on %3$s',
'args' => array(
$product_name,
(string) $stock,
$site_title,
),
);
}//end switch
}