Automattic\WooCommerce\Internal\StockNotifications\AsyncTasks

NotificationsProcessor::parse_product │ private │ WC 1.0

Parse the product.

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

Хуков нет.

Возвращает

\WC_Product.

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

// private - только в коде основоного (родительского) класса
$result = $this->parse_product( $product_id ): WC_Product;
$product_id(int) (обязательный)
The product ID.

Код NotificationsProcessor::parse_product() WC 11.2.2

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;
}