MySQL Query to Get All Coupon

MySQL Query to Get All Coupon

WooCommerce Coupon Graphics

One of my answer in StackOverflow on Question How WooCommerce Coupons are stored in Database? has got many hits, So I thought to put a whole query in this tutorial which might help other developers.

Let me know in the comment if this helps you or not if it helps then do hit the FB like button and share with other WooCommerce developers.

Share this Post:

About Raunak Gupta

I'm an expert Laravel, WooCommerce, WordPress theme and plugin developer, over the time I have developed several sites and applications. I like to help the upcoming developer, So I share my experience through this blog.  

Related Posts:

7 thoughts on “MySQL Query to Get All Coupon

    Paweł Banachowicz

    Hello. Could You please take a look:

    I saw You solved similar matter. thanks


    Good, this is what I was searching for in google


    Hello, i want to select and delete all 30 percent coupons from my database, how can i do that ?

    • Hi Robert,

      Here is the WP_Query which will fetch all the coupon having 30% discount, now you just needs to loop it and delete it using wp_delete_post( int $postid, bool $force_delete = false )

      $args = [
      	'numberposts' => -1,
      	'post_type' => 'shop_coupon',
      	'meta_query' => [
      		'relation' => 'AND',
      			'key' => 'discount_type',
      			'value' => 'percent',
      			'compare' => '=',
      			'key' => 'coupon_amount',
      			'value' => '30',
      			'compare' => '=',
      $query = new WP_Query($args);

      Hope it helps!


    Hi, this is great, thank you!
    Is it possible to somehow also add detail of the customer that used the coupon? Like their name or email address?
    all my coupons has a usage limit of 1.

    Thank you


    Hi, thank for tutorial, but how to import coupon in database table?

    • Hi Andry,

      If you run this query in phpMyAdmin then you will get an option to export the resultset in the form of CSV.


Leave a Reply to Andry Cancel reply

Your email address will not be published. Required fields are marked *