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

Tutorials

How to Speed Up Your WordPress Restaurant Website: Image Optimization, Caching, Database Cleanup, and Core Web Vitals Fixes for Faster Menu Loading and Checkout (Complete Guide)

Why Restaurant Website Speed Matters More Than You Think A hungry customer pulls up your restaurant’s website on their phone during a lunch break. They’ve got maybe 15 minutes to place an order for pickup. Your homepage takes four seconds to load, the menu images trickle in one by one, and the checkout page freezes […]
April 5, 2026
Tutorials

How to Make Your WooCommerce Restaurant Ordering Website ADA Compliant and Accessible: Screen Reader Optimization, Keyboard Navigation, and WCAG 2.1 Guidelines for Online Menus and Checkout (Complete Guide)

Why Accessibility and ADA Compliance Matter for Restaurant Ordering Websites A customer with low vision tries to order dinner from your restaurant website. They navigate to your menu, but their screen reader can’t parse the item names because they’re embedded in images without alt text. The “Add to Cart” button is invisible to keyboard navigation. […]
April 5, 2026
Tutorials

How to Add Restaurant Schema Markup to Your WordPress Menu Pages: Rich Snippets for Menu Items, Pricing, Reviews, and Cuisine Type to Boost Click-Through Rates in Google Search (Complete Guide)

What Is Restaurant Schema Markup and Why It Matters for Your WordPress Food Ordering Site When someone searches “best margherita pizza near me,” Google doesn’t just show ten blue links anymore. It pulls star ratings, price ranges, cuisine types, and even individual menu items directly into the search results. That extra visual information — called […]
April 5, 2026