WC_Product_Importer::get_variation_parent_attributes()
Get variation parent attributes and set "is_variation".
Method of the class: WC_Product_Importer{}
No Hooks.
Return
Array
.
Usage
// protected - for code of main (parent) or child class $result = $this->get_variation_parent_attributes( $attributes, $parent );
- $attributes(array) (required)
- Attributes list.
- $parent(WC_Product) (required)
- Parent product data.
WC_Product_Importer::get_variation_parent_attributes() WC Product Importer::get variation parent attributes code WC 9.3.1
protected function get_variation_parent_attributes( $attributes, $parent ) { $parent_attributes = $parent->get_attributes(); $require_save = false; foreach ( $attributes as $attribute ) { $attribute_id = 0; // Get ID if is a global attribute. if ( ! empty( $attribute['taxonomy'] ) ) { $attribute_id = $this->get_attribute_taxonomy_id( $attribute['name'] ); } if ( $attribute_id ) { $attribute_name = wc_attribute_taxonomy_name_by_id( $attribute_id ); } else { $attribute_name = sanitize_title( $attribute['name'] ); } // Check if attribute handle variations. if ( isset( $parent_attributes[ $attribute_name ] ) && ! $parent_attributes[ $attribute_name ]->get_variation() ) { // Re-create the attribute to CRUD save and generate again. $parent_attributes[ $attribute_name ] = clone $parent_attributes[ $attribute_name ]; $parent_attributes[ $attribute_name ]->set_variation( 1 ); $require_save = true; } } // Save variation attributes. if ( $require_save ) { $parent->set_attributes( array_values( $parent_attributes ) ); $parent->save(); } return $parent_attributes; }