How to Disable Coupons for Delivery Orders in WooCommerce

June 20, 2023

WooFood

If you’re running a WooCommerce-powered restaurant or food delivery service, you might want to restrict certain coupon codes for delivery orders while keeping them valid for pickup orders. This ensures better control over discounts, prevents misuse, and improves your store’s pricing strategy.

Why Restrict Coupons for Delivery Orders?

Offering coupons is a great way to attract customers, but in food delivery businesses, you may want to limit their usagefor:
✔ Preventing discounts on delivery orders where margins are lower
✔ Allowing coupon usage only for pickup orders
✔ Ensuring accurate pricing and preventing unintended losses

How to Disable Coupons for Delivery Orders in WooCommerce

To disable a WooCommerce coupon for delivery orders while keeping it valid for pickup, add the following code snippet to your child theme’s functions.php file:

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( 'woofood_order_type') == "delivery")
      {
        return false;
      }
      }
      
    }
  }
  
    return $is_valid;
}

Best Practices for Implementing This Code

✅ Replace "YOURCOUPONCODEHERE" with the actual coupon code you want to restrict.
✅ Test the code in a staging environment before deploying it live.
✅ Ensure that your WooCommerce setup and other plugins don’t conflict with this customization.

Need an Easier Way to Manage WooCommerce Restaurant Orders?

If you’re running a restaurant or food delivery service on WooCommerce, you need a seamless order management solution. Instead of manually restricting coupons and handling orders, you can use WooFood – WooCommerce Food Delivery Plugin.

With WooFood, you can:
✅ Accept pickup and delivery orders effortlessly
✅ Set up custom discounts and pricing rules based on order type
✅ Optimize the checkout experience for faster food ordering

👉 Check out WooFood to streamline your WooCommerce food delivery business today! 🚀