Hide Add to cart button for specific product variations
-
Hi team, I am trying to hide for specific product variations the Add to Cart button. I found a snippet which should do the work but somehow doesnt work for me. I created and attribute test and a value test. But the add to cart button shows anyway. Can you let me know how I could solve that?
add_filter( 'woocommerce_variation_is_purchasable', 'conditional_variation_is_purchasable', 20, 2 ); function conditional_variation_is_purchasable( $purchasable, $product ) { ## ---- Your settings ---- ## $taxonomy = 'test'; $term_name = 'test'; ## ---- The active code ---- ## $found = false; // Loop through all product attributes in the variation foreach ( $product->get_variation_attributes() as $variation_attribute => $term_slug ){ $attribute_taxonomy = str_replace('attribute_', '', $variation_attribute); // The taxonomy $term = get_term_by( 'slug', $term_slug, $taxonomy ); // The WP_Term object // Searching for attribute 'pa_size' with value 'XL' if($attribute_taxonomy == $taxonomy && $term->slug == $term_name ){ $found = true; break; } } if( $found ) $purchasable = false; return $purchasable; }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Hide Add to cart button for specific product variations’ is closed to new replies.