Automattic\WooCommerce\StoreApi\Utilities

CartController::get_variable_product_attributes()protectedWC 1.0

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() WC 8.7.0

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();
}