Support » Plugin: WooCommerce » Add surcharge depending on total

Viewing 3 replies - 1 through 3 (of 3 total)
  • This might help:

    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 = ”);

    }

    Also, I’m noticing the first bit of code (posted below) produces an error upon PayPal checkout. The error I get from Paypal is “The link you have used to enter the PayPal system contains an incorrectly formatted item amount.”

    /**
    * Add a 1% surcharge to your cart / checkout
    * change the $percentage to set the surcharge to a value to suit
    * Uses the WooCommerce fees API
    *
    * Add to theme functions.php
    */
    add_action( ‘woocommerce_cart_calculate_fees’,’woocommerce_custom_surcharge’ );
    function woocommerce_custom_surcharge() {
    global $woocommerce;

    if ( is_admin() && ! defined( ‘DOING_AJAX’ ) )
    return;

    $percentage = 0.01;
    $surcharge = ( $woocommerce->cart->cart_contents_total + $woocommerce->cart->shipping_total ) * $percentage;
    $woocommerce->cart->add_fee( ‘Surcharge’, $surcharge, true, ‘standard’ );

    }

    Found a solution – Bolder Fees for WooCommerce 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Add surcharge depending on total’ is closed to new replies.