排除多个产品ID的WordPress优惠券插件与php

mm9b1k5b  于 2022-12-17  发布在  WordPress
关注(0)|答案(1)|浏览(99)

如何让这段代码调用多个产品,而不是像现在这样只调用一个产品?

add_filter( 'woocommerce_coupon_is_valid_for_product', 'quadlayers_exclude_product_from_product_promotions', 9999, 4 );
function quadlayers_exclude_product_from_product_promotions( $valid, $product, $coupon, $values ) {
// PRODUCT ID = 813869026091
if ( 813869026091 == $product->get_id() ) {
$valid = false;
}
return $valid;
}```

I am trying to get this statement to say if the id is 005 OR 077 then exclude it from the coupon.  Right now I can only get 1 ID in the code (I don't know PHP very well.  Thank you
jutyujz0

jutyujz01#

add_filter( 'woocommerce_coupon_is_valid_for_product', 'quadlayers_exclude_product_from_product_promotions', 9999, 4 );

function quadlayers_exclude_product_from_product_promotions( $valid, $product, $coupon, $values ) {

    if ( in_array($product->id, [1, 3, 5] ) {
        $valid = false;
    }

    return $valid;
}

相关问题