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

How to Modify Booking Price Based on Selected Variation and Fixed Block Pricing in Booking and Appointment plugin for WooCommerce?

The fixed block pricing feature lets you set specific rates for different time periods. Typically, for variable products, when prices are set in the Fixed Block Booking settings of the Booking and Appointment Plugin in WooCommerce, the booking cost calculation combines the variation prices with the fixed block price.

To simplify this and to prevent confusion, you can use a simple code snippet that will set a fixed booking price based on selected variations and fixed block pricing values as set in the code.

Solution: Modify Booking Price Based on Selected Variation and Fixed Block Pricing in Booking and Appointment plugin for WooCommerce

Let’s imagine a luxury dress rental service with a variation price range of $100-$300. If the fixed block pricing feature is set, then while the customer is booking the service, the variation price is added to the fixed block price, creating confusion in the booking cost. Instead, the code snippet allows you to set a fixed rate for each variation ID and also define the fixed block pricing, ensuring that variation prices will not be considered in the booking cost calculation.

/**
 * This will modify the variation price based on the selected variation and fixed block.
 *
 * @param string $price Price.
 * @param int    $product_id Product ID.
 * @param int    $variation_id Variation ID.
 * @param string $product_type Type of Product.
 * @param string $checkin_date Check-in Date.
 * @param string $checkout_date Check-out Date.
 */
function bkap_custom_price_for_fixed_block( $price, $product_id, $variation_id, $product_type, $checkin_date, $checkout_date ) {

	if ( '' != $variation_id ) {

		$number_of_days = strval( $_POST['diff_days'] );
		$var_id         = strval( $variation_id );
		$custom_price   = array(
			'2198' => array( '14' => 2000, '30' => 3000 ), // 2198 - Variation ID of Gold color variation.
			
			
			'2196' => array( '14' => 4000, '30' => 5000 ), // 2196 - Variation ID of Blush Pink color variation.
                       '2197' => array( '14' => 5000, '30' => 6000 ), // 2197 - Variation ID of White color variation.
			
		);

		if ( isset( $custom_price[ $variation_id ][ $number_of_days ] ) ) { // check if variation price is set for selected number of days.
			$price = $custom_price[ $variation_id ][ $number_of_days ];
		}
	}

	return $price;
}
add_filter( 'bkap_custom_price_for_fixed_block', 'bkap_custom_price_for_fixed_block', 10, 6 );

Output

Before examining the output, let’s look at the variations created in the backend and the different price values set for each of them, as shown in the following images.

How to Modify Booking Price Based on Selected Variation and Fixed Block Pricing in Booking and Appointment plugin for WooCommerce? - Tyche Softwares

The price value for the variation color “Gold” is set to $100, “Blush Pink” is set to $200, and “White” is set to $300.

How to Modify Booking Price Based on Selected Variation and Fixed Block Pricing in Booking and Appointment plugin for WooCommerce? - Tyche Softwares

The fixed block pricing for the product “Designer Wear Dresses For Rent” is set to $1000 for a 14-day fixed block and $2000 for a 30-day fixed block.

How to Modify Booking Price Based on Selected Variation and Fixed Block Pricing in Booking and Appointment plugin for WooCommerce? - Tyche Softwares

Let’s consider a customer who is booking a luxury dress for rent and selects the variation color “Gold” (ID 2198) with a fixed block of “Fourteen Days” for the booking period. Even though the variation booking price for the color “Gold” is set to $100 and the fixed block pricing is set to $1000 for one week, the code will modify the booking cost according to the prices set in the code, specifically $2000 for the 14-day fixed block and the variation ID 2198.

How to Modify Booking Price Based on Selected Variation and Fixed Block Pricing in Booking and Appointment plugin for WooCommerce? - Tyche Softwares

When the code is not implemented, the booking costs are calculated based on both the fixed block pricing set in the backend and the variation prices. Both values are considered, and the final calculation is done by adding the variation price to the fixed block price based on the options selected by the customer.

How to Modify Booking Price Based on Selected Variation and Fixed Block Pricing in Booking and Appointment plugin for WooCommerce? - Tyche Softwares

From the above implementation, store owners will find it easier to implement such customizations for variable products setup. You don’t have to rely solely on the basic options that come with the plugin which happens in most cases of variable products setup. Explore similar customization that will restrict adding variation price to the fixed block price setup in the backend.

Custom codes like this are designed to add additional functionalities based on unique business requirements. We hope you find this useful! If you have any specific requirements, let us know in the comments.

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