Hi,
As far as we understand, this issue happens only after you’ve uploaded some product variations, and the memory exhaustion occurs on one specific page?
Since your situation is more complex than simply asking, “Would performance be better if…,” let us explain how the plugin and WooCommerce work in a nutshell, so you can debug and find the solution.
- The WooCommerce Role Based Pricing plugin doesn’t calculate and display prices or price ranges directly. It uses WooCommerce hooks (e.g.,
woocommerce_get_price
, woocommerce_get_variation_price
) to send pricing data to WooCommerce, which then performs the necessary calculations.
- In the case of variable products, WooCommerce caches the price calculations to avoid querying the database on every request. It uses WordPress’s transient API to store the price data temporarily. The most resource-intensive operation with variations is calculating the price ranges (
_min_variation_price
, _max_variation_price
).
- When WooCommerce needs to display the price of a variable product on the front end (e.g., in a product archive, single product page, or, in your case, the homepage), it checks the cached transients for the minimum and maximum variation prices. If these cached values exist, WooCommerce uses them directly, which speeds up page load times. If the transients are expired or missing (e.g., after product updates or cache clearing), WooCommerce recalculates the prices by querying the database for the variation prices and updates the transient values.
- WooCommerce only recalculates variation prices under specific circumstances: when you manually edit the price of a variation in the admin, when the product’s status changes (e.g., from draft to published), when a variation’s sale period starts or ends, or if the transient cache expires (which can be controlled via hooks or cache plugins).
- With the WooCommerce Role Based Pricing plugin, when a user role requests the price of a product that hasn’t been calculated yet and price ranges aren’t stored in the transient cache, WooCommerce processes the calculations for each variation (requested by the user). Once the calculations are complete, WooCommerce stores the data in transients. This process shouldn’t repeat unless the transients are cleared (due to the reasons listed in p.4).
- By default, an average hosting plan should handle the operation of calculating price ranges and caching transients for a reasonable number of variations without hitting the memory limit. However, this depends on how many variations each variable product has, how many variable products are requested at the same time, and your server’s capacity.
Therefore, the issue with hitting the memory limit may be caused by several factors:
- It may happen only during the first pricing calculations for a new user role if too many products are requested at once and your server doesn’t have the capacity to process such queries.
- It may happen because something is triggering WooCommerce transients to be cleared, which means WooCommerce has to reprocess calculations and regenerate the cache repeatedly. This could happen for reasons listed in p.4 above, or because some plugins request transients to be cleared due to their specific needs.
- You may have a large number of variable products on the requested page (e.g., hundreds) with many variations in each product, and your server may not have the resources to process the query.
Recommendations:
You can use Query Monitor or any other plugin or server tool that helps identify bottlenecks and slow queries. Specifically, look for:
- Queries taking too long (generally anything above 0.1 seconds),
- Repeated queries (the same query running multiple times in one request),
- Queries by Component (to see if a specific plugin, theme, or even WooCommerce is responsible for the slow queries).
You can also track how long various Woo hooks and actions are taking to see what’s consuming the majority of server resources.
Additionally, check the number of variable products being requested on one page. It could be that you’re trying to load hundreds of variable products, and some of them don’t retrieve transient data, triggering WooCommerce to initiate calculations instead. In that case, it might be better to limit the number of variable products per page or use something like Lazy Load to retrieve data in smaller portions.