Automattic\WooCommerce\Internal\PushNotifications\Triggers
StockNotificationRecoveryHandler::on_stock_change
Evaluates each event subtype's recovery threshold and clears the corresponding sent-meta when the new stock level has recovered.
Method of the class: StockNotificationRecoveryHandler{}
No Hooks.
Returns
null. Nothing (null).
Usage
$StockNotificationRecoveryHandler = new StockNotificationRecoveryHandler(); $StockNotificationRecoveryHandler->on_stock_change( $product ): void;
- $product(WC_Product) (required)
- The product whose stock changed.
Changelog
| Since 10.9.0 | Introduced. |
StockNotificationRecoveryHandler::on_stock_change() StockNotificationRecoveryHandler::on stock change code WC 10.9.1
public function on_stock_change( WC_Product $product ): void {
$product_id = $product->get_id();
if ( $product_id <= 0 ) {
return;
}
$stock_quantity = $product->get_stock_quantity();
if ( null === $stock_quantity ) {
return;
}
$stock = (int) $stock_quantity;
if ( $stock > (int) wc_get_low_stock_amount( $product ) ) {
$this->clear_meta( $product_id, StockNotification::EVENT_LOW_STOCK );
}
if ( $stock > (int) get_option( 'woocommerce_notify_no_stock_amount', 0 ) ) {
$this->clear_meta( $product_id, StockNotification::EVENT_OUT_OF_STOCK );
}
if ( $stock >= 0 ) {
$this->clear_meta( $product_id, StockNotification::EVENT_ON_BACKORDER );
}
}