Automattic\WooCommerce\Internal\StockNotifications
StockSyncController::handle_product_stock_status_change
Handle product stock status changes.
Method of the class: StockSyncController{}
No Hooks.
Returns
null. Nothing (null).
Usage
$StockSyncController = new StockSyncController(); $StockSyncController->handle_product_stock_status_change( $product_id, $stock_status, $product );
- $product_id(int) (required)
- The product ID.
- $stock_status(string) (required)
- The new stock status.
- $product(WC_Product|null)
- The product object (optional).
Default: null
StockSyncController::handle_product_stock_status_change() StockSyncController::handle product stock status change code WC 10.3.6
public function handle_product_stock_status_change( $product_id, $stock_status, $product = null ) {
try {
if ( ! $this->eligibility_service->is_stock_status_eligible( $stock_status ) ) {
return;
}
if ( null === $product ) {
$product = \wc_get_product( $product_id );
}
if ( ! is_a( $product, 'WC_Product' ) ) {
return;
}
if ( ! $this->eligibility_service->is_product_eligible( $product ) ) {
return;
}
if ( ! $this->eligibility_service->has_active_notifications( $product ) ) {
return;
}
// Add to queue.
$target_product_ids = $this->eligibility_service->get_target_product_ids( $product );
foreach ( $target_product_ids as $target_product_id ) {
$this->queue[ $target_product_id ] = true;
}
$this->store_admin_notice( $product->get_id() );
} catch ( \Throwable $e ) {
$this->logger->error(
sprintf( 'StockSyncController: Failed to process product %d: %s', $product_id, $e->getMessage() ),
array( 'source' => 'wc-customer-stock-notifications' )
);
}
}