Automattic\WooCommerce\Internal\PushNotifications\Notifications
StockNotification::build_message
Builds the message payload for the notification.
Метод класса: StockNotification{}
Хуков нет.
Возвращает
Массив{format:. string, args: string[]}
Использование
// private - только в коде основоного (родительского) класса $result = $this->build_message( $product_name, $site_title, $product ): array;
- $product_name(строка) (обязательный)
- The sanitized product name.
- $site_title(строка) (обязательный)
- The sanitized site title.
- $product(WC_Product) (обязательный)
- The product object (used as a fallback when no trigger-time stock was captured).
Код StockNotification::build_message() StockNotification::build message 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
}