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).
Method of the class: CartController{}
No Hooks.
Returns
Array.
Usage
// protected - for code of main (parent) or child class $result = $this->get_variable_product_attributes( $product );
- $product(WC_Product) (required)
- Product being added to the cart.
CartController::get_variable_product_attributes() CartController::get variable product attributes code WC 10.8.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();
}