Automattic\WooCommerce\Internal\StockNotifications\AsyncTasks
NotificationsProcessor::parse_product
Parse the product.
Method of the class: NotificationsProcessor{}
No Hooks.
Returns
\WC_Product.
Usage
// private - for code of main (parent) class only $result = $this->parse_product( $product_id ): WC_Product;
- $product_id(int) (required)
- The product ID.
NotificationsProcessor::parse_product() NotificationsProcessor::parse product code WC 10.3.6
private function parse_product( int $product_id ): WC_Product {
$product = wc_get_product( $product_id );
if ( ! $product instanceof WC_Product ) {
throw new \Exception( sprintf( 'Product %d not found.', absint( $product_id ) ) );
}
if ( ! $this->eligibility_service->is_product_eligible( $product ) ) {
throw new \Exception( sprintf( 'Product %d is not eligible for notifications.', $product->get_id() ) ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
}
if ( ! $this->eligibility_service->is_stock_status_eligible( $product->get_stock_status() ) ) {
throw new \Exception( sprintf( 'Product %d stock status is not eligible for notifications (i.e. not in stock).', $product->get_id() ) ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
}
return $product;
}