Cart total discount

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

Posted in

Comments

3 responses to “Cart total discount”

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

    Cheers

  2. Rocco Di Fonso Avatar
    Rocco Di Fonso

    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. 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

Share