Automattic\WooCommerce\Internal\ProductFeed\Mapping
UcpProductMapper::term_names
Index term names by slug for each variation attribute of a product.
Method of the class: UcpProductMapper{}
No Hooks.
Returns
array. Attribute label => [ slug => term name ].
Usage
// private - for code of main (parent) class only $result = $this->term_names( $item ): array;
- $item(array) (required)
- Store API item response of the variable product.
UcpProductMapper::term_names() UcpProductMapper::term names code WC 11.3.0
private function term_names( array $item ): array {
$names = array();
foreach ( (array) $item['attributes'] as $attribute ) {
if ( empty( $attribute['has_variations'] ) ) {
continue;
}
foreach ( (array) $attribute['terms'] as $term ) {
$names[ (string) $attribute['name'] ][ (string) $term['slug'] ] = (string) $term['name'];
}
}
return $names;
}