WordPress.org

Forums

WooCommerce - excelling eCommerce
Add surcharge depending on total (4 posts)

  1. joinfof
    Member
    Posted 1 year ago #

    I am using WooCommerce and would like to add certain fees to the customer's final total depending on their subtotal.

    For example, if their subtotal is:

    Less than $8.99 | $7.99 fee
    $9-$24.99 | x% fee
    $25-$49.99 | y% fee
    $50-$99.99 | z% fee

    I have found documentation from the developer that adds a pre-determined % surcharge correctly, but I would like to have more precise structure. You can see it here: http://docs.woothemes.com/document/add-a-surcharge-to-cart-and-checkout-uses-fees-api/

    Can anyone help me out?

    https://wordpress.org/plugins/woocommerce/

  2. joinfof
    Member
    Posted 1 year ago #

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

    }

  3. joinfof
    Member
    Posted 1 year ago #

    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' );

    }

  4. joinfof
    Member
    Posted 1 year ago #

    Found a solution - Bolder Fees for WooCommerce :-)

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WooCommerce - excelling eCommerce
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic