woocommerce add fee to cart based on quantity

前端 未结 1 1104
清酒与你
清酒与你 2020-12-20 02:55

I wan to add fee based on quantity. For eg: If quantity in cart = 5 , then the fee to be added should be 4$, If quantity in cart = 7, then the fee to be added

相关标签:
1条回答
  • 2020-12-20 03:26

    Please Try this

    function woocommerce_custom_surcharge(){ 
    global $woocommerce;
    //Getting Cart Contents. 
    $cart = $woocommerce->cart->get_cart();
    //Calculating Quantity
    foreach($cart as $cart_val => $cid){
            $qty += $cid['quantity']; 
        }
    //Your Condition
    if($qty==5)
    {
        $excost = 7;
        }
        else if($qty==7){
        $excost = 8;
        }
    
        $woocommerce->cart->add_fee('Charges delivery', $excost, $taxable = false, $tax_class = '');
    
    
    }
    

    From Here I found that We need to get the quantity of the cart by summing up the values of the cart.Hope this will Solve your problem.

    0 讨论(0)
提交回复
热议问题