WooCommerce Discount based on Cart Item

A discount on the total order with condition based on our cart item

We will give a discount on the total order with condition based on our cart item.

Here is the basic structure of our code

function.php
//discount 
add_action('woocommerce_cart_calculate_fees' , 'custom_discount', 10, 1);
function custom_discount( $cart ){

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

     // Iterating through each item in cart
	$discount = 0;
	foreach( $cart->get_cart() as $cart_item ){
		// Getting an instance of the product object
		$product =  $cart_item['data'];
		
		$sub_total = $product->tc_price1;
		
		if ($sub_total>1000) {
			$discount += -10;
		}
		
		
	}

	## Applied discount (no products on sale) ##
	$cart->add_fee( 'Buffet over $1000 order', $discount);
		
}
Previous Code

Jquery Replace specific text in all element

TweetShareSharePin0 Shares ...

Next Code

Replace add to cart button with the product page link & Change add to cart text

`Replace add to cart button with product single li ...

1 Comment

Leave a Reply

Your email address will not be published.

fifteen − eleven =

Remove WooCommerce checkout fields

Remove WooCommerce Checkout field with simple filt ...

Get WooCommerce product info

Show product info in the place as you wish to. It ...

WooCommerce Checkout Conflict with Bootstrap 4.x

WooCommerce Checkout Conflict with Bootstrap 4.x. ...

Update WooCommerce Delivery cost with condition

Change Delivery price base on what item in cart ...

Replace add to cart button with the product page link & Change add to cart text

`Replace add to cart button with product single li ...

ACF

JavaScript

jQuery

Others

PHP

WooCommerce

WordPress

skype

Need Coding Help?

Connect Skype
top