Automattic\WooCommerce\Internal\StockNotifications\Frontend
SignupService::parse_product
Parse the product from the source data.
Метод класса: SignupService{}
Хуков нет.
Возвращает
\WC_Product|\WP_Error. The product, or a WP_Error if the product is invalid.
Использование
// private - только в коде основоного (родительского) класса $result = $this->parse_product( $source );
- $source(массив) (обязательный)
- The source data, e.g.
$_POSTor$_REQUEST.
Код SignupService::parse_product() SignupService::parse product WC 11.2.2
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;
}