WC_Product_CSV_Importer::parse_tags_field()publicWC 1.0

Parse a tag field from a CSV.

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

Хуков нет.

Возвращает

Массив.

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

$WC_Product_CSV_Importer = new WC_Product_CSV_Importer();
$WC_Product_CSV_Importer->parse_tags_field( $value );
$value(строка) (обязательный)
Field value.

Код WC_Product_CSV_Importer::parse_tags_field() WC 8.7.0

public function parse_tags_field( $value ) {
	if ( empty( $value ) ) {
		return array();
	}

	$value = $this->unescape_data( $value );
	$names = $this->explode_values( $value );
	$tags  = array();

	foreach ( $names as $name ) {
		$term = get_term_by( 'name', $name, 'product_tag' );

		if ( ! $term || is_wp_error( $term ) ) {
			$term = (object) wp_insert_term( $name, 'product_tag' );
		}

		if ( ! is_wp_error( $term ) ) {
			$tags[] = $term->term_id;
		}
	}

	return $tags;
}