diff --git a/includes/class-wc-product-variation.php b/includes/class-wc-product-variation.php index 2204f85d963..ccb80f21be6 100644 --- a/includes/class-wc-product-variation.php +++ b/includes/class-wc-product-variation.php @@ -598,7 +598,6 @@ class WC_Product_Variation extends WC_Product_Simple { return false; } - wp_delete_object_term_relationships( $variation_id, wc_get_attribute_taxonomy_names() ); return true; } } diff --git a/includes/data-stores/class-wc-product-variable-data-store-cpt.php b/includes/data-stores/class-wc-product-variable-data-store-cpt.php index 0f09da96679..eeece0d2d61 100644 --- a/includes/data-stores/class-wc-product-variable-data-store-cpt.php +++ b/includes/data-stores/class-wc-product-variable-data-store-cpt.php @@ -661,7 +661,6 @@ class WC_Product_Variable_Data_Store_CPT extends WC_Product_Data_Store_CPT imple if ( $force_delete ) { do_action( 'woocommerce_before_delete_product_variation', $variation_id ); wp_delete_post( $variation_id, true ); - wp_delete_object_term_relationships( $variation_id, wc_get_attribute_taxonomy_names() ); do_action( 'woocommerce_delete_product_variation', $variation_id ); } else { wp_trash_post( $variation_id ); diff --git a/includes/data-stores/class-wc-product-variation-data-store-cpt.php b/includes/data-stores/class-wc-product-variation-data-store-cpt.php index fddea2d2374..5dd45b04536 100644 --- a/includes/data-stores/class-wc-product-variation-data-store-cpt.php +++ b/includes/data-stores/class-wc-product-variation-data-store-cpt.php @@ -495,21 +495,6 @@ class WC_Product_Variation_Data_Store_CPT extends WC_Product_Data_Store_CPT impl foreach ( $delete_attribute_keys as $key ) { delete_post_meta( $product_id, $key ); } - - // Set the attributes as regular taxonomy terms too... - $variation_attributes = array_keys( $product->get_variation_attributes( false ) ); - foreach ( $attributes as $name => $value ) { - $value = strval( $value ); - if ( '' !== $value && in_array( $name, $variation_attributes, true ) && term_exists( $value, $name ) ) { - wp_set_post_terms( $product_id, array( $value ), $name ); - } elseif ( taxonomy_exists( $name ) ) { - wp_delete_object_term_relationships( $product_id, $name ); - } - } - - // ...and remove old taxonomy terms. - $attributes_to_delete = array_diff( wc_get_attribute_taxonomy_names(), array_keys( $attributes ) ); - wp_delete_object_term_relationships( $product_id, $attributes_to_delete ); } } diff --git a/tests/legacy/unit-tests/product/product-variation.php b/tests/legacy/unit-tests/product/product-variation.php index c8102764cce..4767adb1f78 100644 --- a/tests/legacy/unit-tests/product/product-variation.php +++ b/tests/legacy/unit-tests/product/product-variation.php @@ -114,20 +114,4 @@ class WC_Tests_Product_Variation extends WC_Unit_Test_Case { $actual = $sut->get_variation_attributes( $with_prefix ); $this->assertEquals( $expected, $actual ); } - - /** - * @testdox Test that the delete method removes the attribute terms for the variation. - */ - public function test_delete_removes_attribute_terms() { - $product = WC_Helper_Product::create_variation_product(); - $sut = wc_get_product( $product->get_children()[2] ); - $id = $sut->get_id(); - - $sut->delete( true ); - - $attribute_names = wc_get_attribute_taxonomy_names(); - $variation_attribute_terms = wp_get_post_terms( $id, $attribute_names ); - - $this->assertEmpty( $variation_attribute_terms ); - } } diff --git a/tests/unit-tests/product/class-wc-tests-product-variable-data-store-cpt.php b/tests/unit-tests/product/class-wc-tests-product-variable-data-store-cpt.php deleted file mode 100644 index 46b5c9b30a1..00000000000 --- a/tests/unit-tests/product/class-wc-tests-product-variable-data-store-cpt.php +++ /dev/null @@ -1,29 +0,0 @@ -get_children()[2] ); - $variation_id = $variation->get_id(); - - $sut = new WC_Product_Variable_Data_Store_CPT(); - $sut->delete_variations( $product->get_id(), true ); - - $attribute_names = wc_get_attribute_taxonomy_names(); - $variation_attribute_terms = wp_get_post_terms( $variation_id, $attribute_names ); - - $this->assertEmpty( $variation_attribute_terms ); - } -} diff --git a/tests/unit-tests/product/class-wc-tests-product-variation-data-store-cpt.php b/tests/unit-tests/product/class-wc-tests-product-variation-data-store-cpt.php deleted file mode 100644 index b38b9a2dcdf..00000000000 --- a/tests/unit-tests/product/class-wc-tests-product-variation-data-store-cpt.php +++ /dev/null @@ -1,137 +0,0 @@ -set_attributes( array( $attr_size, $attr_color ) ); - $product->save(); - - $variation = WC_Helper_Product::create_product_variation_object( - $product->get_id(), - 'SMALL RED THING', - 10, - array( - 'pa_size' => 'small', - 'pa_color' => 'red', - ) - ); - - return $variation; - } - - /** - * Return a simplified list with the attribute terms for a variation object. - * - * @param int $variation_id Id of the variation product. - * - * @return array Attributes as an "attribute"=>"term" associative array. - */ - private function get_attribute_terms_for_variation( $variation_id ) { - $attribute_names = wc_get_attribute_taxonomy_names(); - $variation_attribute_terms = wp_get_post_terms( $variation_id, $attribute_names ); - $terms = array(); - foreach ( $variation_attribute_terms as $term ) { - $terms[ $term->taxonomy ] = $term->name; - } - return $terms; - } - - /** - * @testdox Test that attribute terms are created for new variations. - */ - public function test_attribute_terms_are_created_for_new_variations() { - $variation = $this->create_variation_object_for_existing_variable_product(); - - $sut = new WC_Product_Variation_Data_Store_CPT(); - $sut->create( $variation ); - - $terms = $this->get_attribute_terms_for_variation( $variation->get_id() ); - - $expected = array( - 'pa_size' => 'small', - 'pa_color' => 'red', - ); - - $this->assertEquals( $expected, $terms ); - - $variation->set_attributes( - array( - 'pa_size' => 'large', - 'pa_color' => 'blue', - ) - ); - - $sut->update( $variation ); - - $terms = $this->get_attribute_terms_for_variation( $variation->get_id() ); - - $expected = array( - 'pa_size' => 'large', - 'pa_color' => 'blue', - ); - - $this->assertEquals( $expected, $terms ); - } - - /** - * @testdox Test that attribute terms are updated for updated variations. - */ - public function test_attribute_terms_are_updated_for_modified_variations() { - $variation = $this->create_variation_object_for_existing_variable_product(); - - $sut = new WC_Product_Variation_Data_Store_CPT(); - $sut->create( $variation ); - - $new_attributes = array( - 'pa_size' => 'small', - 'pa_color' => 'red', - ); - $variation->set_attributes( $new_attributes ); - $sut->update( $variation ); - - $terms = $this->get_attribute_terms_for_variation( $variation->get_id() ); - - $this->assertEquals( $new_attributes, $terms ); - } - - /** - * @testdox Test that attribute terms are removed for variations updated with "Any" value. - */ - public function test_attribute_terms_are_removed_for_variations_set_to_any_attribute_value() { - $variation = $this->create_variation_object_for_existing_variable_product(); - - $sut = new WC_Product_Variation_Data_Store_CPT(); - $sut->create( $variation ); - - $new_attributes = array( - 'pa_size' => 'small', - 'pa_color' => '', - ); - $variation->set_attributes( $new_attributes ); - $sut->update( $variation ); - - $terms = $this->get_attribute_terms_for_variation( $variation->get_id() ); - - $expected = array( 'pa_size' => 'small' ); - - $this->assertEquals( $expected, $terms ); - } -}