Automattic\WooCommerce\StoreApi\Schemas\V1

OrderItemSchema::get_parent_product_attributes │ protected │ WC 10.5.0

Get parent product attributes.

Cached to avoid multiple DB lookups when processing multiple meta items.

Метод класса: OrderItemSchema{}

Хуков нет.

Возвращает

array. Array of WC_Product_Attribute objects.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->get_parent_product_attributes( $product );
$product(WC_Product) (обязательный)
Product instance.

Список изменений

С версии 10.5.0 Введена.

Код OrderItemSchema::get_parent_product_attributes() WC 11.2.2

protected function get_parent_product_attributes( $product ) {
	if ( null !== $this->cached_parent_attributes ) {
		return $this->cached_parent_attributes;
	}

	$this->cached_parent_attributes = array();

	if ( ! $product->get_parent_id() ) {
		return $this->cached_parent_attributes;
	}

	$parent_product = wc_get_product( $product->get_parent_id() );
	if ( ! $parent_product instanceof \WC_Product ) {
		return $this->cached_parent_attributes;
	}

	$this->cached_parent_attributes = $parent_product->get_attributes();

	return $this->cached_parent_attributes;
}