if with custom product attributes
-
I am trying to adapt the following code to work with custom attributes (and not with global attributes (pa_) but can’t get it to work. This one is working fine, it’s the unaltered code:
add_filter( 'woocommerce_coupon_is_valid', 'check_if_coupons_are_valid', 10, 3 ); function check_if_coupons_are_valid( $is_valid, $coupon, $discount ){ // YOUR ATTRIBUTE SETTINGS BELOW: $taxonomy = 'pa_xyz'; $term_slugs = array('zyx'); // Loop through cart items and check for backordered items foreach ( WC()->cart->get_cart() as $cart_item ) { foreach( $cart_item['variation'] as $attribute => $term_slug ) { if( $attribute === 'attribute_'.$taxonomy && in_array( $term_slug, $term_slugs ) ) { $is_valid = false; // attribute found, coupons are not valid break; // Stop and exit from the loop } } } return $is_valid; }
So something like if $product_attribute[‘value’] is xxx… any help is really appreciated!
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘if with custom product attributes’ is closed to new replies.