Not working if Product is Variation
-
All in all this plugin does a good job, but there are problems with variations.
I updated the
ut_filter_woo_coupon_is_valid_for_product
method and enhanced it in a quick and dirty way to make it work with product variations:function ut_filter_woo_coupon_is_valid_for_product( $valid, $product, $instance, $values ) { $options = get_post_meta( $instance->get_id(), 'ut_tax_enabled', true ); if ( $options && $options === 'yes' ) { $taxonomies = get_post_meta( $instance->get_id(), 'ut_products_taxonomies', true ); if ( ! $taxonomies || ! is_array( $taxonomies ) ) { return false; } $taxonomy_objects = get_object_taxonomies( 'product', 'objects' ); if ( ! is_array( $taxonomy_objects ) ) { return false; } $all_product_terms = []; foreach ( $taxonomy_objects as $taxonomy_object ) { $product_terms = get_the_terms( $product->get_id(), $taxonomy_object->name ); // check for variations if (is_a($product, 'WC_Product_Variation')) { $parent_product_terms = get_the_terms($product->get_parent_id(), $taxonomy_object->name); foreach ( $parent_product_terms as $product_term ) { array_push( $all_product_terms, $product_term->term_id ); } } if ( is_array( $product_terms ) && count( $product_terms ) > 0 ) { foreach ( $product_terms as $product_term ) { array_push( $all_product_terms, $product_term->term_id ); } } } // finally remove duplicates $all_product_terms = array_unique($all_product_terms); foreach ( $taxonomies as $taxonomy ) { if ( in_array( $taxonomy, $all_product_terms ) ) { return true; } } return false; } return
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Not working if Product is Variation’ is closed to new replies.