Repository › Forums › Support › WooCommerce Extended Coupon Features PRO › slow calculate_totals() – tips? › Reply To: slow calculate_totals() – tips?
I’ve made slight customizations to it to attend to this store’s needs, none have affected performance (i’ve measured them). But to rule out the intrincacies of my custom installation, i went ahead and attempted to isolate the problem (Something that, in retrospect, i see i should’ve done from the beggining). Blank woo with storefront install + latest ECF + a few (6) coupons set to auto. While the amount of miliseconds decreased (to around 400), the trend persisted: update_matched_autocoupons() continued to take around 40% of the server response time.
40% is something that i think we can live with on cart and checkout pages, but not product listing and detail pages.
The biggest question i’m asking myself is: does update_matched_autocoupons have to be hooked to woocommerce_after_calculate_totals? I see that the plugin was coded defensively with the use of add_action_once, but, i can’t help but wonder if that could be further improved, ie: only reevaluate coupons whenever something about the cart does change, and only then. Perhaps adding a middleman? The middleman could be hooked to woocommerce_after_calculate_totals in order to preserve the desired execution order, but it would check wether coupons do need reevaluating before calling update_matched_autocoupons(). Or something along this line.