Site icon Experience Wordpress Developer Online – Design Develop and Maintenance Support

Add Cart Discount based on cart total amount in WooCommerce

I am trying to achieve below functionality in woo-commerce cart page. In my cart page if total price between two product is grater than 150 rs. than need to apply 15% discount on total cart of product price.Same as Also if total price between two product is grater than 100 rs. and less than 150 rs. than need to apply 10% discount on total cart of product price.Same as Also if total price between two product is grater than 50 rs. and less than 100 rs. than need to apply 5% discount on total cart of product price.

Here is the code , Paste this code in your function.php file of your active child theme (or theme).

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

    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return;

    $cart_total = $cart_object->cart_contents_total; // Cart total

    if ( $cart_total > 150.00 )
        $percent = 15; // 15%
    elseif ( $cart_total >= 100.00 && $cart_total = 50.00 && $cart_total add_fee( "Discount ($percent%)", -$discount, true );
    }
}

Here is what you are going to get on cart page.

Exit mobile version