【问题标题】:Exclude several shipping classes from a fee based on cart items dimensions in Woocommerce根据 Woocommerce 中的购物车商品尺寸从费用中排除多个运输类别
【发布时间】:2020-03-25 09:33:30
【问题描述】:

这一年我在这里得到了很大的帮助,关于 woocommerce 问题,我需要根据 this thread 中的总购物车高度自动添加费用,然后在 this thread 中更新宽度。

现在我唯一的问题是我需要从函数中排除一些运输类别,因为它们的运输方式不同并且不需要添加大宗费用。

我一直在玩弄“Add a fee based on cart items dimensions in Woocommerce”的答案,试图给它添加一个类变量:

// Initializing variables $total_height = 0; $class = 1390,1392,1389; $apply_fee = false;

但它会立即破坏网站。我一直在 stackoverflow.com 和 Google 上寻找一种方法来做到这一点,但没有运气,而且我仍然没有足够的资格进行这种类型的高级代码编辑。

感谢我能得到的任何帮助。

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

    你不能有这样的 id 列表,它们之间只有逗号。要解决此问题,请将 ids 放入一个数组中。在 foreach 循环中,检查产品的运输类别 ID,如果它在数组中,则排除它。

        $exclClasses = array(1390,1392,1389);
    
        // Checking item with
        if ( $cart_item['data']->get_width() > $width_threshold ) {
            $apply_fee = true;
        }
    
        // make sure product isn't in excluded shipping classes
        if (in_array( $cart_item['data']->get_shipping_class_id(), $exclClasses)) 
        {
            $apply_fee = false;
        }
    

    或使用 1 条语句代替 2 条

        if ( $cart_item['data']->get_width() > $width_threshold && !in_array( $cart_item['data']->get_shipping_class_id(), $exclClasses)) {
            $apply_fee = true;
        }
    

    【讨论】:

      猜你喜欢
      • 2020-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-19
      • 1970-01-01
      • 1970-01-01
      • 2015-07-27
      • 2018-01-30
      相关资源
      最近更新 更多