【发布时间】:2017-09-07 13:44:54
【问题描述】:
如果购物车的总内容量低于 5,我将使用下面的代码添加运费。
但是,我只希望这适用于不在“配件”类别中的产品。因此,例如,如果用户有 4 个产品,但有 1 个来自“附件”类别的产品,那么它不应该包括添加来自“附件”猫的产品。
我知道我需要使用操作员来测试是否有任何产品属于“附件”类别,如果是则打破陈述,但我不确定我将如何在 Woocommerce 中执行此操作。
谁能帮帮我?
/**
* Add custom fee on article specifics
* @param WC_Cart $cart
*/
function add_custom_fees( WC_Cart $cart ){
$fees = 0;
// Check if odds and if it's the right item
if( $cart->cart_contents_count < 5){
get_post_meta
$fees += 48;
}
if( $fees != 0 ){
$cart->add_fee( 'Delivery charge', $fees);
}
}
【问题讨论】:
标签: php wordpress woocommerce