WPSlash

Add Discount on WooCommerce Checkout when Pickup is selected using WooFood

Thursday April 9, 2020

Here is small snippet you can add a discount on total cart contents . On the following example we are adding a 20% discount when Pickup is selected. You can change the variable $percentage to the number of percentage discount you want.

function wpslash_add_discount_for_pickup() {
	global $woocommerce;
    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
		return;
	$order_type =  WC()->session->get( 'woofood_order_type' );

	$percentage = 20;
	$discount_amount =  $woocommerce->cart->cart_contents_total  * ($percentage/100);	
	if($order_type == "pickup")
	{
			$woocommerce->cart->add_fee( 'Pickup Discount', -$discount_amount, true, '' );

	}

}
add_action( 'woocommerce_cart_calculate_fees','wpslash_add_discount_for_pickup' );

Here is a second sample if you want to add discount on pickup items excluding some ids

function wpslash_add_discount_for_pickup_specific_ids() {
	global $woocommerce;
    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
		return;
	$order_type =  WC()->session->get( 'woofood_order_type' );
        $exluded_ids = array(110, 134);
	$percentage = 20;
foreach( WC()->cart->get_cart() as $cart_item ){
    $product_id= $cart_item['product_id'];
    $price = $cart_item['data']->get_price(); 
    $discount_amount =  $price  * ($percentage/100);	
    $title = $cart_item['data']->get_title(); 

if($order_type == "pickup" && !in_array($product_id, $exluded_ids))
	{
			$woocommerce->cart->add_fee( $title.' Discount', -$discount_amount, true, '' );

	}
}
	
	

}
add_action( 'woocommerce_cart_calculate_fees','wpslash_add_discount_for_pickup_specific_ids' );

Leave a Comment

Your email address will not be published. Required fields are marked *

Related Articles

Restaurants Tutorials

The Cheapest Food Delivery App for Restaurants Isn’t an App at All — It’s WooFood

When restaurant owners start looking for the cheapest food delivery app, they quickly discover a frustrating truth: most “cheap” delivery platforms aren’t cheap at all. They either take commissions, charge high monthly fees, lock you into their payment processors, or limit how much control you have over your own customer base. But what if the […]
December 1, 2025
Restaurants WooFood

Why “Free” GloriaFood Might Not Be The Best Long-Term Bet For Your Restaurant

When you’re building an online ordering system for your restaurant, it’s tempting to go for a “free” solution. That’s exactly what GloriaFood offers: a ready-to-go, easy-to-install WordPress plugin for online ordering, delivery, and reservations with no setup fees or commissions But “free” doesn’t always mean “best,” especially when you’re serious about owning your brand, your […]
December 1, 2025
Tutorials WooCommerce

How to Choose the Best Food Ordering System for Your Restaurant (And Why WooFood is the Ultimate Solution)

If you’re running a restaurant, café, or fast-food business in today’s digital age, offering online food ordering is no longer optional — it’s essential. Customers expect the convenience of browsing your menu, customizing their orders, and checking out seamlessly from their phone or computer. But with so many plugins and systems available, how do you choose the right […]
April 21, 2025