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.
Return
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 8.6.1
protected function get_variable_product_attributes( $product ) { if ( $product->is_type( 'variation' ) ) { $product = wc_get_product( $product->get_parent_id() ); } if ( ! $product || 'trash' === $product->get_status() ) { throw new RouteException( 'woocommerce_rest_cart_invalid_parent_product', __( 'This product cannot be added to the cart.', 'woocommerce' ), 400 ); } return $product->get_attributes(); }