WC_Product_CSV_Importer::parse_tags_field()publicWC 1.0

Parse a tag field from a CSV.

Method of the class: WC_Product_CSV_Importer{}

No Hooks.

Return

Array.

Usage

$WC_Product_CSV_Importer = new WC_Product_CSV_Importer();
$WC_Product_CSV_Importer->parse_tags_field( $value );
$value(string) (required)
Field value.

WC_Product_CSV_Importer::parse_tags_field() code 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;
}