Automattic\WooCommerce\Internal\PushNotifications\Triggers
StockNotificationTrigger::on_low_stock
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.
Method of the class: StockNotificationTrigger{}
No Hooks.
Returns
null. Nothing (null).
Usage
$StockNotificationTrigger = new StockNotificationTrigger(); $StockNotificationTrigger->on_low_stock( $product ): void;
- $product(WC_Product) (required)
- The product whose stock is low.
Changelog
| Since 10.9.0 | Introduced. |
StockNotificationTrigger::on_low_stock() StockNotificationTrigger::on low stock code 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
);
}