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

Removing price re-calculations when a Bookable product is added to cart

Price calculation in WooCommerce booking - WooCommerce Booking and Appointment Plugin

We introduced the multiple day booking feature in version 1.1 of the plugin on July 26 2013. This version handled pricing by simply multiplying the product/variation price with the number of nights. This was a very simple piece of calculation and hence was done individually on the Product page (where the price was displayed) and then on the Cart page (when the product was added to the cart).

We introduced new addons to the booking plugin (Seasonal Pricing Addon, Partial Deposits Addon and so on) that dealt with pricing as well. We created hooks/filters to help with these.

We also went on to add more features to the plugin. This included a variety of pricing options like the Fixed Block pricing, Special Day pricing and so on.

On the way, we were also making our plugin compatible with various other plugins like WPML, WPML Multi Currency, WooCommerce Product Addons, Gravity Forms & few others.

However, the price calculations were still being done individually on the product page & on the cart page. Due to many types of pricing options that we added, it was becoming increasingly difficult to manage separate calculations for both the pages.

It also meant that not only was the processing being done twice, but that the data tables etc. were also being accessed twice leading to an increase in the processing time.

Hence in version 2.4.4 which we released on Dec 17 2015, we decided to remove the price re-calculations that were being done when a bookable product is added to the cart.
We introduced 2 hidden fields to help with this:

1. total_price_calculated
2. bkap_price_charged

These fields contain the unformatted (numeric) amount being charged to the user. The amount in both the fields is always the same except for when the Partial Deposits Addon is being used.

Only when the addon is active and enabled, do the values in these fields vary. The total_price_calculated field contains the total bookable amount and the bkap_price_charged field contains the amount that the user is currently being charged.

When the product is added to the cart, the plugin takes the amount in the bkap_price_charged field and divides it with the quantity being booked (If it is greater than 1) and sets it as the price on the Cart page.

These changes have helped us make the plugin easily compatible with other plugins like WooCommerce Product Bundles ( still in development, to be released by 30 December 2015 ).

Browse more in: Documentation, WooCommerce, WooCommerce Booking & Appointment

Share It:

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