Automattic\WooCommerce\Internal\PushNotifications\Triggers

StockNotificationTrigger::on_low_stockpublicWC 10.9.0

Handles the woocommerce_low_stock hook.

Captures the product's stock quantity at this moment so the dispatcher, which runs in a separate process and re-fetches the product, doesn't read a stale value if cache invalidation hasn't fully propagated.

Метод класса: StockNotificationTrigger{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$StockNotificationTrigger = new StockNotificationTrigger();
$StockNotificationTrigger->on_low_stock( $product ): void;
$product(WC_Product) (обязательный)
The product whose stock is low.

Список изменений

С версии 10.9.0 Введена.

Код StockNotificationTrigger::on_low_stock() WC 10.9.1

public function on_low_stock( WC_Product $product ): void {
	$stock = $product->get_stock_quantity();
	$this->add_notification(
		$product->get_id(),
		StockNotification::EVENT_LOW_STOCK,
		null !== $stock ? (int) $stock : null
	);
}