From 7f92479f4fff13eeb12fc290b59e73b281ce7a3d Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Mon, 22 May 2017 19:24:33 -0300 Subject: [PATCH] Create shipping class or tag if does not exist --- .../import/class-wc-product-csv-importer.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/includes/import/class-wc-product-csv-importer.php b/includes/import/class-wc-product-csv-importer.php index 3caf659f9b9..95b29068fa8 100644 --- a/includes/import/class-wc-product-csv-importer.php +++ b/includes/import/class-wc-product-csv-importer.php @@ -223,9 +223,13 @@ class WC_Product_CSV_Importer extends WC_Product_Importer { $tags = array(); foreach ( $names as $name ) { - if ( $term = get_term_by( 'name', $name, 'product_tag' ) ) { - $tags[] = $term->term_id; + $term = get_term_by( 'name', $name, 'product_tag' ); + + if ( ! $term ) { + $term = wp_insert_term( $name, 'product_tag' ); } + + $tags[] = $term->term_id; } return $tags; @@ -238,11 +242,13 @@ class WC_Product_CSV_Importer extends WC_Product_Importer { * @return int */ protected function parse_shipping_class( $field ) { - if ( $term = get_term_by( 'name', $field, 'product_tag' ) ) { - return $term->term_id; + $term = get_term_by( 'name', $field, 'product_shipping_class' ); + + if ( ! $term ) { + $term = wp_insert_term( $name, 'product_shipping_class' ); } - return 0; + return $term->term_id; } /**