From 922715791c8f76797b95e6e7619cfa3527769052 Mon Sep 17 00:00:00 2001 From: Josh Koberstein Date: Thu, 16 Jul 2015 15:31:14 -0700 Subject: [PATCH 1/2] Passing array of term ids to wp_set_object_terms instead of term names. --- .../meta-boxes/class-wc-meta-box-product-data.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/includes/admin/meta-boxes/class-wc-meta-box-product-data.php b/includes/admin/meta-boxes/class-wc-meta-box-product-data.php index 78240855d41..b77d857efde 100644 --- a/includes/admin/meta-boxes/class-wc-meta-box-product-data.php +++ b/includes/admin/meta-boxes/class-wc-meta-box-product-data.php @@ -901,6 +901,19 @@ class WC_Meta_Box_Product_Data { // Update post terms if ( taxonomy_exists( $attribute_names[ $i ] ) ) { + + foreach( $values as $key => $value ) { + $term = get_term_by( 'name', trim( $value ), $attribute_names[ $i ] ); + if ( $term ) { + $values[ $key ] = intval( $term->term_id ); + } else { + $term = wp_insert_term( trim( $value ), $attribute_names[ $i ] ); + if ( isset( $term->term_id ) ) { + $values[ $key ] = intval($term->term_id); + } + } + } + wp_set_object_terms( $post_id, $values, $attribute_names[ $i ] ); } From 38856b29c4d48b8d223910f001e83e322be4a019 Mon Sep 17 00:00:00 2001 From: Josh Koberstein Date: Thu, 16 Jul 2015 16:02:33 -0700 Subject: [PATCH 2/2] Correcting indentation --- .../class-wc-meta-box-product-data.php | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/includes/admin/meta-boxes/class-wc-meta-box-product-data.php b/includes/admin/meta-boxes/class-wc-meta-box-product-data.php index b77d857efde..9aa6bcddd06 100644 --- a/includes/admin/meta-boxes/class-wc-meta-box-product-data.php +++ b/includes/admin/meta-boxes/class-wc-meta-box-product-data.php @@ -902,17 +902,17 @@ class WC_Meta_Box_Product_Data { // Update post terms if ( taxonomy_exists( $attribute_names[ $i ] ) ) { - foreach( $values as $key => $value ) { - $term = get_term_by( 'name', trim( $value ), $attribute_names[ $i ] ); - if ( $term ) { - $values[ $key ] = intval( $term->term_id ); - } else { - $term = wp_insert_term( trim( $value ), $attribute_names[ $i ] ); - if ( isset( $term->term_id ) ) { - $values[ $key ] = intval($term->term_id); - } - } - } + foreach( $values as $key => $value ) { + $term = get_term_by( 'name', trim( $value ), $attribute_names[ $i ] ); + if ( $term ) { + $values[ $key ] = intval( $term->term_id ); + } else { + $term = wp_insert_term( trim( $value ), $attribute_names[ $i ] ); + if ( isset( $term->term_id ) ) { + $values[ $key ] = intval($term->term_id); + } + } + } wp_set_object_terms( $post_id, $values, $attribute_names[ $i ] ); }