Automattic\WooCommerce\StoreApi\Schemas\V1
OrderItemSchema::get_parent_product_attributes
Get parent product attributes.
Cached to avoid multiple DB lookups when processing multiple meta items.
Method of the class: OrderItemSchema{}
No Hooks.
Returns
Array. Array of WC_Product_Attribute objects.
Usage
// protected - for code of main (parent) or child class $result = $this->get_parent_product_attributes( $product );
- $product(WC_Product) (required)
- Product instance.
Changelog
| Since 10.5.0 | Introduced. |
OrderItemSchema::get_parent_product_attributes() OrderItemSchema::get parent product attributes code WC 10.9.4
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;
}