根据Woocommerce中的购物车项目尺寸从费用中排除多个运输类别



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

现在我唯一的问题是我需要从功能中排除某些运输类别,因为它们的运输方式不同,不需要添加大件费用。

我一直在玩"根据 WooCommerce 中的购物车项目维度添加费用"的答案,尝试向其添加一个类变量:

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

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

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

你不能有一个像这样的 id 列表,它们之间只有逗号。要解决此问题,请将 id 放在数组中。在 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;
}

最新更新