Create shipping class or tag if does not exist

This commit is contained in:
Claudio Sanches 2017-05-22 19:24:33 -03:00
parent 775a934b74
commit 7f92479f4f
1 changed files with 11 additions and 5 deletions

View File

@ -223,9 +223,13 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
$tags = array(); $tags = array();
foreach ( $names as $name ) { foreach ( $names as $name ) {
if ( $term = get_term_by( 'name', $name, 'product_tag' ) ) { $term = get_term_by( 'name', $name, 'product_tag' );
$tags[] = $term->term_id;
if ( ! $term ) {
$term = wp_insert_term( $name, 'product_tag' );
} }
$tags[] = $term->term_id;
} }
return $tags; return $tags;
@ -238,11 +242,13 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
* @return int * @return int
*/ */
protected function parse_shipping_class( $field ) { protected function parse_shipping_class( $field ) {
if ( $term = get_term_by( 'name', $field, 'product_tag' ) ) { $term = get_term_by( 'name', $field, 'product_shipping_class' );
return $term->term_id;
if ( ! $term ) {
$term = wp_insert_term( $name, 'product_shipping_class' );
} }
return 0; return $term->term_id;
} }
/** /**