WC_Brands_Admin::get_column_value_brand_ids()
Get brands column value for csv export.
Метод класса: WC_Brands_Admin{}
Хуков нет.
Возвращает
Строку
. Brands separated by commas and child brands as "parent > child".
Использование
$WC_Brands_Admin = new WC_Brands_Admin(); $WC_Brands_Admin->get_column_value_brand_ids( $value, $product );
- $value(строка) (обязательный)
- What will be exported.
- $product(WC_Product) (обязательный)
- Product being exported.
Код WC_Brands_Admin::get_column_value_brand_ids() WC Brands Admin::get column value brand ids WC 9.4.2
public function get_column_value_brand_ids( $value, $product ) { $brand_ids = wp_parse_id_list( wp_get_post_terms( $product->get_id(), 'product_brand', array( 'fields' => 'ids' ) ) ); if ( ! count( $brand_ids ) ) { return ''; } // Based on WC_CSV_Exporter::format_term_ids(). $formatted_brands = array(); foreach ( $brand_ids as $brand_id ) { $formatted_term = array(); $ancestor_ids = array_reverse( get_ancestors( $brand_id, 'product_brand' ) ); foreach ( $ancestor_ids as $ancestor_id ) { $term = get_term( $ancestor_id, 'product_brand' ); if ( $term && ! is_wp_error( $term ) ) { $formatted_term[] = $term->name; } } $term = get_term( $brand_id, 'product_brand' ); if ( $term && ! is_wp_error( $term ) ) { $formatted_term[] = $term->name; } $formatted_brands[] = implode( ' > ', $formatted_term ); } // Based on WC_CSV_Exporter::implode_values(). $values_to_implode = array(); foreach ( $formatted_brands as $brand ) { $brand = (string) is_scalar( $brand ) ? $brand : ''; $values_to_implode[] = str_replace( ',', '\\,', $brand ); } return implode( ', ', $values_to_implode ); }