Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

How to Apply a Discount for Advance Booking Dates in Booking and Appointment Plugin?

Businesses that offer rental bookings, hotel bookings, tour packages, etc allow customers to reserve services/products for multiple consecutive days. To cater to such needs, there is a Multiple Night booking feature in our Booking and Appointment plugin for WooCommerce to help with such booking functionalities.

For e.g customers can easily book a hotel room for a specific check-in and check-out date range. But that’s not enough-now we are going to leverage this customization to offer exclusive discounts for bookings made by the customer is atleast 4 days in advance from the current date. Let’s understand this with an example.

Imagine a customer is planning a relaxing trip and needs to book a hotel. When he tries to book a hotel online, the store will offer a discount on the booking price for early bookings. For example, if the trip starts on Friday and the customer books the rental by Monday of the same week let’s say four days before, you’ll get a special discount of 50% discount on the total price.

Solution: Apply a Discount for Advance Booking Dates in Booking and Appointment Plugin

The code applies a discount for booking dates after X number of days from the current date in the Booking and Appointment Plugin. Here’s how the below code applies the discount: 50% discount on the booking price if the check-in date is four or more days in advance from the current date.

/**
 * 50% discount if the check-in date is 4 days after the current date.
 *
 * @param array  $cart_arr Cart Array.
 * @param int    $product_id Product ID.
 * @param int    $variation_id Variation ID.
 * @param array  $cart_item_meta Cart Item Array.
 * @param array  $booking_settings Booking Settings.
 * @param object $global_settings Global Booking Settings.
 * 
 * @return array $cart_arr Cart Array.
 */
function bkap_addon_add_cart_item_data( $cart_arr, $product_id, $variation_id, $cart_item_meta, $booking_settings, $global_settings ) {
	$hidden_date   = $cart_arr['hidden_date'];
	$current_time  = current_time( 'timestamp' );
	$current_date  = date( 'j-n-Y', $current_time );
	$booking_date  = new DateTime( $hidden_date );
	$checkout_date = new DateTime( $current_date );
	$difference    = $checkout_date->diff( $booking_date );
	if ( $difference->d > 4 ) { // if checking date is after 4 days. 
		$cart_arr['price'] = $cart_arr['price'] / 2; // 50% discount.
	}
	return $cart_arr;
}
add_filter( 'bkap_addon_add_cart_item_data', 'bkap_addon_add_cart_item_data', 10, 6 );

Output

Let’s consider a customer who is booking a hotel from an online WooCommerce store and using the Booking and Appointment plugin. If the customer’s current date is June 13 and if he proceeds to select a check-in date of June 20 which is 4 or more days in advance from the current date, then the code applies a 50% discount to the cart item price.

How to Apply a Discount for Advance Booking Dates in Booking and Appointment Plugin? - Tyche Softwares

The discount will be applied to the cart item price as the customer has booked 4 days earlier from the current date.

How to Apply a Discount for Advance Booking Dates in Booking and Appointment Plugin? - Tyche Softwares

Let’s also look into the scenario where the booking is done for a check-in date 2 days in advance (June 15th) from the current date of June 13. In this case, the discount will not be applied as the condition of booking at least 4 days in advance from the current date has not been met.

How to Apply a Discount for Advance Booking Dates in Booking and Appointment Plugin? - Tyche Softwares


Offering discounts for advance bookings is a great way to encourage customers to make their reservations earlier. With the Booking & Appointment Plugin for WooCommerce, this customization is easy to implement with just a handy snippet. If you are looking for similar customization, feel free to let us know in the comment section.

Browse more in: Code Snippets, WooCommerce Booking & Appointment, WooCommerce How Tos

Share It:

Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x