From 63552c97577a97cffa54cbbc1ba8e7bf731fef5b Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Wed, 3 May 2017 16:30:50 -0300 Subject: [PATCH] Fixed conflict between global attributes and custom attributes. Check if is a custom attribute before trying to get an ID from a global attribute. --- .../admin/meta-boxes/class-wc-meta-box-product-data.php | 9 +++++++-- includes/data-stores/class-wc-product-data-store-cpt.php | 7 +++++-- 2 files changed, 12 insertions(+), 4 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 fb95174dd5b..2d7fc3bf4c6 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 @@ -225,9 +225,14 @@ class WC_Meta_Box_Product_Data { if ( empty( $attribute_names[ $i ] ) || ! isset( $attribute_values[ $i ] ) ) { continue; } + $attribute_id = 0; $attribute_name = wc_clean( $attribute_names[ $i ] ); - $attribute_id = wc_attribute_taxonomy_id_by_name( $attribute_name ); - $options = isset( $attribute_values[ $i ] ) ? $attribute_values[ $i ] : ''; + + if ( 'pa_' === substr( $attribute_name, 0, 3 ) ) { + $attribute_id = wc_attribute_taxonomy_id_by_name( $attribute_name ); + } + + $options = isset( $attribute_values[ $i ] ) ? $attribute_values[ $i ] : ''; if ( is_array( $options ) ) { // Term ids sent as array. diff --git a/includes/data-stores/class-wc-product-data-store-cpt.php b/includes/data-stores/class-wc-product-data-store-cpt.php index 887965d982e..1582303fb90 100644 --- a/includes/data-stores/class-wc-product-data-store-cpt.php +++ b/includes/data-stores/class-wc-product-data-store-cpt.php @@ -369,6 +369,7 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da if ( ! empty( $meta_values ) && is_array( $meta_values ) ) { $attributes = array(); foreach ( $meta_values as $meta_value ) { + $id = 0; $meta_value = array_merge( array( 'name' => '', 'value' => '', @@ -378,17 +379,20 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da 'is_taxonomy' => 0, ), (array) $meta_value ); + // Check if is a taxonomy attribute. if ( ! empty( $meta_value['is_taxonomy'] ) ) { if ( ! taxonomy_exists( $meta_value['name'] ) ) { continue; } + $id = wc_attribute_taxonomy_id_by_name( $meta_value['name'] ); $options = wc_get_object_terms( $product->get_id(), $meta_value['name'], 'term_id' ); } else { $options = wc_get_text_attributes( $meta_value['value'] ); } $attribute = new WC_Product_Attribute(); - $attribute->set_id( wc_attribute_taxonomy_id_by_name( $meta_value['name'] ) ); + + $attribute->set_id( $id ); $attribute->set_name( $meta_value['name'] ); $attribute->set_options( $options ); $attribute->set_position( $meta_value['position'] ); @@ -652,7 +656,6 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da } elseif ( $attribute->is_taxonomy() ) { wp_set_object_terms( $product->get_id(), wp_list_pluck( $attribute->get_terms(), 'term_id' ), $attribute->get_name() ); - } else { $value = wc_implode_text_attributes( $attribute->get_options() ); }