• Resolved dnlcrd

    (@stardeslebens)


    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)
  • Mirko P.

    (@rainfallnixfig)

    Hi @stardeslebens,

    This is a more development-oriented question. I’ll go ahead and leave this thread open for a while to see if anyone is able to chime in to help you out.

    I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.

    You can also visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Cheers!

    Plugin Support AW a11n

    (@slash1andy)

    Automattic Happiness Engineer

    Hey there!

    Since there’s not been responses here, I’m going to mark this as resolved – if you have any further questions, you can start a new thread.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘if with custom product attributes’ is closed to new replies.