When using the Booking and Appointment Plugin in WooCommerce, you can add extra resources uisng the Resources Tab. For example, when choosing a music system, you might want to include additional resources like DJ services or extra speakers, depending on how many you need. Normally, the total cost of your booking is calculated based on the product price, the price of any added resources, and how many quantity you select. This can lead to pricing inconsistencies and confusion for customers.
So, with this customization, we adjust how resources are priced. Instead of multiplying the cost of each resource by the quantity you select, we only factor in the product’s booking price and the quantity chosen. This means the total cost doesn’t increase based on how many resources you add,but rather based on how many quantity of the booking product is selected.
Solution: Avoid Calculating the Resource Price According to the Quantity in the Booking and Appointment Plugin for WooCommerce
The code will modify the booking price by excluding the quantity-based calculation of resource costs.
Note: This customization works only when the option ‘Consider Product’s Max Booking’ is enabled from the backend of the booking settings.
![How to Avoid Calculating the Resource Price According to the Quantity in the Booking and Appointment Plugin for WooCommerce? 1 How to Avoid Calculating the Resource Price According to the Quantity in the Booking and Appointment Plugin for WooCommerce? - Tyche Softwares](https://media.tychesoftwares.com/wp-content/uploads/consider-products-max-booking-1024x553.png)
/** * Do not calculate the resource price according to quantity. * * @param float $time_slot_price Price. * @param int $product_id Product ID. * @param int $variation_id Variation ID. * @param string $product_type Product Type. */ function bkap_modify_booking_price( $time_slot_price, $product_id, $variation_id, $product_type ){ if ( isset( $_POST['resource_id'] ) && '' != $_POST['resource_id'] ) { $resource_id = $_POST['resource_id']; $resource = new BKAP_Product_Resource( $resource_id, $product_id ); $resource_price = $resource->get_base_cost(); if ( 0 != $resource_price ) { $time_slot_price = $time_slot_price - $resource_price; $resource_price = $resource_price / $_POST['quantity']; $time_slot_price = $time_slot_price + $resource_price; } } return $time_slot_price; } add_filter( 'bkap_modify_booking_price', 'bkap_modify_booking_price', 10, 4 );
Output
When a customer selects 2 units of a music system priced at $200 each, and adds DJ services as a resource priced at $100, the total booking price is $500. The cost of the resources (DJ services) is not multiplied by the number of units of the music system selected.
![How to Avoid Calculating the Resource Price According to the Quantity in the Booking and Appointment Plugin for WooCommerce? 2 How to Avoid Calculating the Resource Price According to the Quantity in the Booking and Appointment Plugin for WooCommerce? - Tyche Softwares](https://media.tychesoftwares.com/wp-content/uploads/Booking-cost-is-calculated-based-on-product-quantity-resource-cost-is-fixed-763x1024.png)
Before implementing the code, the pricing for resources is also considered based on selected quantity.
![How to Avoid Calculating the Resource Price According to the Quantity in the Booking and Appointment Plugin for WooCommerce? 3 How to Avoid Calculating the Resource Price According to the Quantity in the Booking and Appointment Plugin for WooCommerce? - Tyche Softwares](https://media.tychesoftwares.com/wp-content/uploads/Resource-cost-is-also-multiplied-according-to-the-booking-quantity-736x1024.png)
In the Booking and Appointment plugin, there are multiple options available in the resource module for handling bookings based on resources. These customizations can be tailored to meet your specific needs, such as removing resource prices from the dropdown or changing the text for selecting resources on the shop page. Feel free to share your requirements with us in the comments.