Cart total discount

Posted in

Hi again,

I am giving a 10% discount if the cart total is > €100 with the following code:


add_action( \'woocommerce_cart_calculate_fees\', \'progressive_discount_based_on_cart_total\', 10, 1 );
function progressive_discount_based_on_cart_total( $cart_object ) {

if ( is_admin() && ! defined( \’DOING_AJAX\’ ) )
return;
$cart_total = $cart_object->cart_contents_total;

if ( $cart_total > 100.00 )
$percent = 10;
else
$percent = 0;

if ( $percent != 0 ) {
$discount = $cart_total * $percent / 100;
$cart_object->add_fee( \”Sconto $percent%\”, -$discount, true );
}
}

BUT Affiliates Pro calculates the Rate before the discount is applied.
How can I set the correct calculation after the -10% (when necessary) ?

Thank you

3 Responses to Cart total discount

  1. George November 16, 2019 at 6:14 pm #

    That’s great Rocco, good to hear you resolved it.

    Cheers

  2. Rocco Di Fonso November 14, 2019 at 2:21 pm #

    Hi George,

    At the end I managed it using woocommerce_before_cart in order to apply and remove a coupon.

    I have another question now, and I will open a new thread to keep things clean.

    Thank you

  3. George November 6, 2019 at 2:16 pm #

    Hi Rocco,

    Many thanks for using our plugins.

    This occurs because you’re adding a fee and Affiliates won’t take fees into account. IMO you should either apply a coupon programmatically or apply the discount before calculate totals ie using the action woocommerce_before_calculate_totals.

    Please let me know if it worked for you.

    Kind regards,
    George

We use cookies to optimize your experience on our site and assume you're OK with that if you stay.
OK, hide this message.

Affiliates · Contact · Jobs · Terms & Conditions · Privacy Policy · Documentation · Downloads · Useful Plugins · My Account

Share