Critical Performance Issue
-
Hi WebToffee Support Team,
I am running WT Smart Coupons on a high-traffic WooCommerce store (40,000+ customers, 350 orders/day) and have identified a critical performance issue that is causing severe CPU spikes and slow page loads across the entire site.
The Problem
On every single page load — including homepage, product pages, blog posts, and all non-cart pages — the plugin fires
maybe_auto_apply_on_wp_loaded()which callsget_available_auto_coupons()which runsis_coupon_valid()for every single auto-apply coupon we have.We have 171 auto-apply coupons. Each validation call triggers
validate_coupon_usage_limit()which internally callswc_get_orders()— a heavy database query. This means:171 coupons × wc_get_orders() = 171+ heavy DB queries per page load Total coupon-related queries per page = 223We confirmed this via PHP slow log analysis and SAVEQUERIES debug output.
PHP Slow Log Evidence
mysqli_query() wc_get_orders() validate_coupon_usage_limit() is_coupon_valid() get_available_auto_coupons() ← line 219 auto_apply_coupons() ← line 532 maybe_auto_apply_on_wp_loaded() ← line 718This stack appears 3,439 times in a single day’s slow log.
The Root Cause
maybe_auto_apply_on_wp_loaded()currently runs on every page load with no restriction to cart or checkout pages. For stores with many auto-apply coupons this causes massive unnecessary DB load on every page — even pages where cart functionality is completely irrelevant. It should fire relevant places like add to cart happens in ajax on single product page or cart update happens etc.Why We Cannot Fix It Ourselves
We attempted restricting
maybe_auto_apply_on_wp_loaded()to cart/checkout pages via a filter onwt_sc_auto_coupons_listreturning[]on non-cart pages. This causedremove_unmatched_autocoupons()to incorrectly remove BOGO coupons from active carts because they were not in the empty valid list.We also attempted editing the plugin file directly to add an
is_cart() || is_checkout()check — this broke cart removal functionality becauseremove_unmatched_autocoupons()was no longer running on non-cart pages.The fix needs to be done at the plugin level with full awareness of how
remove_unmatched_autocoupons()and BOGO interact.Our Setup
- WooCommerce 10.2.2
- WT Smart Coupons v2.2.2 (also tested v2.2.9 — same issue)
- 171 auto-apply coupons (all active, all in use)
- 0 coupons with usage limits
- Cloudways server, Object Cache Pro / Redis active
- ~150,000 page requests per day
Impact
- PHP slow log shows 3,439+ coupon-related slow frames per day
- CPU spikes during US peak hours causing site slowdowns
- Every visitor on every page triggers 223 DB queries just for coupon checking
This is a significant scalability issue for any store with a large number of auto-apply coupons. We would greatly appreciate a fix or official guidance in your next release.
Thank you for your time.
You must be logged in to reply to this topic.