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

How to Display Price × Number of Days Calculation in Cart and Checkout Pages with WooCommerce Booking and Appointment Plugin?

Businesses that offer services based on time durations, such as hotel rooms, car rentals, or equipment hire bookings using the WooCommerce Booking and Appointment plugin, need to focus on displaying cost calculations in a straightforward and easy-to-understand format. With transparent pricing details displayed to customers on the cart and checkout pages, they can check the calculation once and are more likely to complete their booking.

Solution: Display Price × Number of Days Calculation in Cart and Checkout with WooCommerce Booking and Appointment Plugin

The code will display the correct breakdown of cost calculation such as per day price * number of nights in the subtotal to ensure accurate information is presented to customers.

function bkap_woocommerce_cart_item_subtotal( $product_subtotal, $cart_item, $cart_item_key ) {

	if ( isset( $cart_item['bkap_booking'] ) ) {
		
		$booking = $cart_item['bkap_booking'][0];
		if ( isset( $booking[ 'hidden_date_checkout' ] ) ) {
			$checkin_date_str  = strtotime( $booking[ 'hidden_date' ] );
			$checkout_date_str = strtotime( $booking[ 'hidden_date_checkout' ] );
			$checkin_date      = date( 'Y-m-d', $checkin_date_str );
			$checkout_date     = date( 'Y-m-d', $checkout_date_str );
			$number_of_days    = $checkout_date_str - $checkin_date_str;
			$no_of_nights      = floor( $number_of_days / 86400 );
			$per_day_price     = $booking[ 'price' ] / $no_of_nights;
			$product_subtotal = wc_price( $per_day_price ) . ' x ' . $no_of_nights . ' nights = ' . $product_subtotal;
		}
	}
	return $product_subtotal;
}
add_filter( 'woocommerce_cart_item_subtotal', 'bkap_woocommerce_cart_item_subtotal', 10, 3 );

Output

When a customer books a hotel, they will see the accurate cost breakdowns on both the cart and checkout pages. For instance, if the booking costs $100 per day and they book for 3 nights, it will display “100 x 3 nights = $300”, providing clear pricing details throughout the booking process.

How to Display Price × Number of Days Calculation in Cart and Checkout Pages with WooCommerce Booking and Appointment Plugin? - Tyche Softwares

The dynamic calculation of the subtotal display for booking products is also reflected in the checkout page as shown below.

How to Display Price × Number of Days Calculation in Cart and Checkout Pages with WooCommerce Booking and Appointment Plugin? - Tyche Softwares

Providing such real-time and accurate pricing information based on customer selections improves the user experience while booking. Likewise, you can also dynamically apply discounts if customers made the booking in advance or early from the current date. This allows customers to plan ahead, while store owners can manage their inventory and resources better.

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

Share It:

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