This snippet sets a different minimum delivery amount for each store location in FoodMaster (formerly WooFood). Add it to your child theme’s functions.php file, or to a code snippets plugin.
Set the minimum amount per store
The snippet checks the store id sent with the checkout. Replace the ids 35 and 34 and the amounts 20 and 25 with your own.
<?php
add_action( 'woocommerce_checkout_process', 'woofood_custom_hook_minimum_per_store', 9999999 );
function woofood_custom_hook_minimum_per_store() {
global $woocommerce;
if (isset($_POST["extra_store_name"])) {
//35 is the store id //
if ($_POST["extra_store_name"] == "35")
{
wc_add_notice(
sprintf( __( 'You must have an order with a minimum of %s to place your order, your current order total is %s.', 'woofood-plugin' ) ,
wc_price( 20 ),
wc_price( WC()->cart->subtotal )
), 'error'
);
}
//34 is the store id //
else if($_POST["extra_store_name"] == "34")
{
wc_add_notice(
sprintf( __( 'You must have an order with a minimum of %s to place your order, your current order total is %s.', 'woofood-plugin' ) ,
wc_price( 25 ),
wc_price( WC()->cart->subtotal )
), 'error'
);
}
}
}
?>How the snippet works
The function woofood_custom_hook_minimum_per_store() runs on woocommerce_checkout_process. It reads extra_store_name from the posted checkout data and, when the value matches a store id in the snippet, adds an error notice with wc_add_notice(). The notice shows the minimum amount and the current cart subtotal, and it stops the order from going through.
Before you start
- Set up your store locations in FoodMaster first, so the store ids exist.
- Change the store ids and the amounts in the snippet to match your own locations.
- Test on a staging site before you use it on the live shop.
To check it worked, choose a store at the checkout and place a test order. The error notice should appear with the minimum amount for that store.
FoodMaster (formerly WooFood)
The snippet uses hooks from FoodMaster (formerly WooFood), the restaurant ordering plugin for WooCommerce. You can get FoodMaster here.
