WPSlash Licences

How to Disable Coupons for Delivery Orders in WooCommerce

How to Disable Coupons for Delivery Orders in WooCommerce – code snippet guide from WPSlash
Published
Updated
Reading time
1 minutes
Written by
WPSlash team

This snippet blocks one coupon code on delivery orders and leaves it valid on pickup orders. It reads the order type that FoodMaster (formerly WooFood) stores in the WooCommerce session. Add it to your child theme’s functions.php file, or to a code snippets plugin.

Disable one coupon code for delivery orders

Updated for current FoodMaster versions: the code below uses the foodmaster_ names. Older installs that still run WooFood used the woofood_ prefix, so on those change foodmaster_ back to woofood_.

Code
add_filter( 'woocommerce_coupon_is_valid', 'wpslash_hook_disable_coupon_code_for_delivery', 10, 3 );
function wpslash_hook_disable_coupon_code_for_delivery( $is_valid, $coupon, $discount ){
    if (!is_admin())
    {

   
    $coupon_code_to_apply = "YOURCOUPONCODEHERE";
    if($coupon == $coupon_code_to_apply)
    {
      if(WC()->session)
      {
        if (WC()->session->get( 'foodmaster_order_type') == "delivery")
      {
        return false;
      }
      }
      
    }
  }
  
    return $is_valid;
}

How the snippet works

  • It hooks into woocommerce_coupon_is_valid, which decides whether a coupon can be applied.
  • It compares the coupon with the code you put in $coupon_code_to_apply. Replace "YOURCOUPONCODEHERE" with your own coupon code.
  • If the session holds foodmaster_order_type as delivery, it returns false and the coupon is rejected.
  • On pickup orders, and for every other coupon, it returns the value it was given, so the coupon still works.

To check it worked, add an item to the cart, choose delivery and try the coupon. It should be refused. Switch the order to pickup and the same coupon should apply.

FoodMaster (formerly WooFood)

The snippet relies on the order type stored by FoodMaster (formerly WooFood), the restaurant ordering plugin for WooCommerce, which handles pickup and delivery orders. You can get FoodMaster here.

FoodMasterRestaurant ordering for WooCommerce: delivery, pickup and dine-in, a POS for counter and phone orders, a kitchen display and automatic ticket printing. Used by 10,000+ restaurants.$499 for one site
All guides

FoodMaster (formerly WooFood)12 min read

Best Store Address Setup for Pickup

Compare single-address, multi-location, and directions-first pickup setups to reduce wrong-door visits and simplify checkout.

The plugins these guides are about

FoodMaster for restaurants, courier vouchers for the Greek market, marketplace sync and store tools, all for WooCommerce.

Browse plugins30-day money-back on every plugin