Add Discount on WooCommerce Checkout when Pickup is selected using WooFood

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' );