Automattic\WooCommerce\Internal\StockNotifications\Frontend
SignupService::parse_product
Parse the product from the source data.
Method of the class: SignupService{}
No Hooks.
Returns
\WC_Product|\WP_Error. The product, or a WP_Error if the product is invalid.
Usage
// private - for code of main (parent) class only $result = $this->parse_product( $source );
- $source(array) (required)
- The source data, e.g. $_POST or $_REQUEST.
SignupService::parse_product() SignupService::parse product code WC 10.3.6
private function parse_product( array $source ) {
$product_id = isset( $source['wc_bis_product_id'] ) ? absint( wp_unslash( $source['wc_bis_product_id'] ) ) : false;
if ( ! $product_id ) {
return new \WP_Error( self::ERROR_INVALID_PRODUCT );
}
$product = wc_get_product( $product_id );
if ( ! $product instanceof \WC_Product ) {
return new \WP_Error( self::ERROR_INVALID_PRODUCT );
}
if ( ! $this->eligibility_service->is_product_eligible( $product ) ) {
return new \WP_Error( self::ERROR_INVALID_PRODUCT );
}
if ( ! $this->eligibility_service->product_allows_signups( $product ) ) {
return new \WP_Error( self::ERROR_INVALID_PRODUCT );
}
return $product;
}