Posts

news icon

WooCommerce 2.4 – Dealing with the new price cache

WooCommerce 2.4 price cache – Pros and cons

If you wrote a WooCommerce plugin that works with product prices, and found out that it returns incorrect results when you process variable products, the cause could be the new price caching logic added in WooCommerce 2.4. This new logic, which is not extensively documented, was introduced to increase performance of sites with complex variable products (i.e. products with 20 variations or more).

To reduce processing and calculations, when WooCommerce retrieves the prices of a variable product , it stores them in a dedicated cache, and returns the stored data from that moment on, until the product is modified. When this happens, none of the hooks associated with product price calculations runs, and your code is will probably not run as it should. For example, if your plugin returns different prices depending on custom criteria, you will notice that this no longer happens, and that you will always see the same prices. Those prices come from the cache.

Two of our plugins were affected by this new caching mechanism: our multi-currency solution, the Currency Switcher, and our Prices by Country plugin. In both cases, we had to find a way to work around the limitation of having static prices shown to the customer, while still trying to keep the performance at a good level. Our plugins are now up to date, as we announced earlier, and we thought of sharing our approach, so that it can benefit other developers.

Solutions

Based on our tests, there are two solutions to this issue. The first is the best compromise between flexibility and performance, while the second can come useful if your code absolutely needs to get “raw”, live data.

1. Change the cache key for the prices, depending on your criteria

This solution allows to keep the price caching in place, while still keeping the data dynamic, choosing the correct one depending on arbitrary criteria. For example, suppose that a variable product should show two different set of prices:

  • Prices for wholesalers
  • Prices for the public

Your criteria, in this case, would be “customer is wholesaler“. You can then use it to ensure that the correct prices are loaded for the product. You can find an example showing how you can do this here: WooCommerce 2.4 – Price cache workaround – Dynamic key.

2. Disable the price cache entirely

This solution is no longer applicable as of WooCommerce 2.5

This solution will always give you access to live product prices, but it will disable price caching entirely. We would recommend not to use it, unless necessary. You can find the code here: WooCommerce 2.4 – Price cache workaround – Disable cache.

Conclusion

The new price caching system was unexpected and, although we understand why it was introduced, it can cause quite a bit of confusion. We hope that our examples will help you getting your product back on track, and add full compatibility with WooCommerce 2.4. If you have any questions, please feel free to contact us. You can also leave your feedback in the comments section, below.

The Aelia Team

news icon

Prices by Country now allows regional sale restrictions!

Prices by Country can now restrict sales per region

We have released an update for our WooCommerce Prices By Country plugin (one week ahead of schedule), with the new selective availability feature. The plugin now allows you to make products unavailable for specific regions, while leaving them available for other regions.

Rather than writing a long explanation on how this feature works, we prepared some screenshots that can quickly illustrate it.

Products’ regional availability

Great feature! How can I get it?

The feature is already included in the latest version of the Prices by Country plugin. If you have already purchased it, simply download the updated plugin using the link you received with your order. If you don’t have the plugin yet, you can buy it now. Don’t forget to use our New Year discount coupon to get 15% off the price!

news icon

Prices by Country plugin will support selective availability

Selective availability for products is coming!

We are extending our Prices by Country plugin for WooCommerce so that it will allow to make products unavailable for specific region. This new feature will finally allow shop owners to make some products available only to specific countries, while still allowing customers to buy other ones.

A creative use of this feature would be the creation of split and mixed catalogues. For example, a shop could be configured as follows:

  • Product A, B, and C available to Europe.
  • Product X, Y and Z available to the US and Canada.
  • Product Common1, Common2 and Common3 available to all regions.

With such setup, visitors from Europe will see all Common products and products A, B and C, while visitors from the US and Canada would see all Common products and products X, Y and Z.

Another use of such feature would be restricting the sale of some products to customers within the European union, to avoid having to deal with the new EU VAT MOSS regulations. Simply configure a region containing all EU countries (except your own, if you live in the EU) and customers from the EU won’t be able to purchase the “unavailable” products. Of course, if you would rather become fully compliant, our free, premium WooCommerce EU VAT Assistant plugin can help!

Sneak peek

The selective availability feature is still in active development, but here are a few preview screenshots to give you an idea of how it will work:

I can’t wait to use the feature! What’s the progress?

The feature is now working correctly for simple products, and we will have to implement it for variable products. We hope to release it officially by the 15th of January. Of course, feedback and suggestions are always welcome! If you would like to drop us a line, please feel free to contact us.

The Aelia Team

Aelia Foundation Classes for WooCommerce, now with automatic updates!

Aelia Foundation Classes (AFC) for WooCommerce and has been updated to version 1.1.3.140910.

What’s new

This new version brings just one improve, yet a very big one. From this version on, the plugin will automatic updates.

That’s right! We installed an automatic updates service on our web servers, and the Aelia Foundation Classes plugin will now use it to determine when new updates are available. It will then show a notifications in the Administration area, and also allow to install updates automatically, just like standard WordPress plugins.

Sounds great! How can I get it?

Simply click on the link above to get the latest version of the Aelia Foundation Classes for WooCommerce. The plugin is completely free. Once installed, you will automatically be informed of new updates, and you will be able to install them with one click. Housekeeping just became much easier!

AFC for WooCommerce and Easy Digital Downloads updated to v1.0.12.140908

Aelia Foundation Classes (AFC) for WooCommerce and for Aelia Foundation Classes (AFC) for Easy Digital Downloads have been updated to version 1.0.12.140908.

What’s new

  • Improved logic used for session handling. The new logic includes additional checks to ensure that the session is available before using it.
  • Added preliminary information to allow automatic updates of the plugin. We are now working on implementing automatic updates for both the AFC plugins. This will simplify the management and maintenance of plugins which are based on it.

How to download the latest version

Simply click on the links above. The plugins are completely free.

Subscriptions Integration for Currency Switcher updated to version 1.2.3.140715

Subscriptions Integration Add-on for Currency Switcher for WooCommerce 2.0.x/2.1.x has been updated to version 1.2.6.140820. This update brings the following improvements and fixes:

  • Improved logic used for requirements and dependency checking.
  • Improved compatibility with 3rd party plugins, such as WooCommerce Booking.

Important: Subscriptions Integration Add-on requires Currency Switcher 3.3.11.140619 or later.

How to get latest version

You can download the plugin from the product page, free of charge. Support can be purchased separately.