Automattic\WooCommerce\StoreApi\Utilities
CartController::get_variable_product_attributes
Get product attributes from the variable product (which may be the parent if the product object is a variation).
Метод класса: CartController{}
Хуков нет.
Возвращает
Массив.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->get_variable_product_attributes( $product );
- $product(WC_Product) (обязательный)
- Product being added to the cart.
Код CartController::get_variable_product_attributes() CartController::get variable product attributes WC 11.0.1
protected function get_variable_product_attributes( $product ) {
if ( $product->is_type( ProductType::VARIATION ) ) {
$product = wc_get_product( $product->get_parent_id() );
}
if ( ! $product || ProductStatus::TRASH === $product->get_status() ) {
throw new RouteException(
'woocommerce_rest_cart_invalid_parent_product',
esc_html__( 'This product cannot be added to the cart.', 'woocommerce' ),
400
);
}
return $product->get_attributes();
}