Clean up the expired/used up coupons [RESOLVED]

Hi team, I’ve been using snippets to auto-generate coupons for returning customers and now there’re so many used-up coupons in the admin coupon list and it’s occupying massive page height.

I want to clean up the used-up coupons and those expired coupons, but as there are too many, I cannot delete it one by one, is there a better way to sort out all the coupons in the database? For example by searching for the condition:
usage limit = usage count, or expiration exceeds certain date.

I cannot seem to find the coupon field in the database, I found in gf_entry_meta but it doesn’t contain the meta values like usage limit and usage count…

Could anyone help me with this? Thanks!

Coupons are actually stored in the gf_addon_feed table. The coupon limit and usage count are part of the JSON stored in the meta column.

1 Like

Thanks for the tips Richard!

If your database has the JSON functions, which, I think, were introduced around MySQL 5.7, try the following:

SELECT * 
FROM `wp_gf_addon_feed` 
WHERE `addon_slug` = 'gravityformscoupons' 
AND JSON_UNQUOTE(JSON_EXTRACT(`meta`, '$.usageLimit')) = JSON_UNQUOTE(JSON_EXTRACT(`meta`, '$.usageCount'));
2 Likes

It works like a charm! Greatly appreciate that :smiling_face_with_three_hearts:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.