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

How to Optimize Duration Pricing in Booking and Appointment Plugin Based on Selected Durations?

Our Booking and Appointment Plugin for WooCommerce follows a tiered pricing model when the booking type is duration-based booking. This means if the booking price of the product is set to 100, then the cost for a 1-hour duration is $100, and for 2 hours it is $200, and so on.

But in case you want to change this pricing logic and set customized price for each timeslot, you can effortlessly achieve this using the code snippet below. Let’s dive in to learn how to customize the pricing based on appointment durations.

Solution: Optimize Duration Pricing in Booking and Appointment Plugin Based on Selected Durations

The code snippet will dynamically change the final price calculation based on selected time-slots of specific products when using the Booking and Appointment Plugin.

/** 
 * Manipulating the Duration price based on the selected duration.
 * 
 * @param string $final_price Final Price Calculated based on the Settings
 * @param string $product_id Product ID
 * @param string $booking_settings Booking Settings
 * @param string $post POST data 
 */
function bkap_final_duration_price_callback( $final_price, $product_id, $booking_settings, $post ) {
        // here 2587 is Product ID, array is the combination of duration => price
	$prices = array(
				'62' => array( '1' => '1000', '2' => '1500', '3' => '2000', '4' => '2750' ),  // 1 = 30 mins, 2 = 1 hour, 3 = 1.5 hour, 4 = 2 hours
				'2589' => array( '1' => '20', '2' => '30', '3' => '35', '4' => '45' ),
			);
	
	if ( in_array( $product_id, array_keys( $prices ) ) ) {
		$price_basedon_durations = $prices[ $product_id ];
		$selected_duration       = $post['bkap_duration'];
		$final_price             = isset( $price_basedon_durations[ $selected_duration ] ) ? $price_basedon_durations[ $selected_duration ] : $final_price;
	}

	return $final_price;
}
add_filter( 'bkap_final_duration_price', 'bkap_final_duration_price_callback', 10, 4 );

Output

As shown in the image, if the original price of the booking product is $25 we will set a customized prices based on the selected duration. When a customer selects this booking service for 1 hour, the code will adjust the booking price to $100 based on the specific time and price settings as defined in the code.

How to Optimize Duration Pricing in Booking and Appointment Plugin Based on Selected Durations? - Tyche Softwares

While the above customization helps you to apply pricing strategies based on selected duration. What if you want to set a fixed rate irrespective of any hour selected by the customer? Don’t worry! We have covered even that. You can try this customization that will set fixed booking cost to 1 hour duration in WooCommerce Booking and Appointment plugin.

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
Launch Alert: Flexi BOGO for WooCommerce! Create irresistible holiday discount sales with ease.Learn more
0
Would love your thoughts, please comment.x
()
x