doulei3488 2019-07-03 19:00
浏览 32

使用优惠券获取某个属性无效(已完成一些代码)

I am trying to get it so the coupons do not work with anything with the attribute of extract-flavor = agave.

There are 2 Extract Flavors Coconut Oil & Agave - I want agave to be invalid with ALL coupons

I have tried the below code, it just makes all coupons invalid

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_extract-flavor';
     $term_slugs = 'agave';

     // 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 ) {
                $is_valid = false; // attribute found, coupons are not valid
                break; // Stop and exit from the loop
               }
          }
        }
         return $is_valid;
        }

I expect it to make all coupons being used on the extract flavors that is agave invalid, but it makes all coupons invalid on all products

thanks

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
    • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
    • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
    • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
    • ¥15 运动想象脑电信号数据集.vhdr
    • ¥15 三因素重复测量数据R语句编写,不存在交互作用
    • ¥15 微信会员卡等级和折扣规则
    • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
    • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
    • ¥15 gdf格式的脑电数据如何处理matlab