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

  1. p.banachowicz@gmail.com'
    Paweł Banachowicz

    Hello. Could You please take a look:

    https://stackoverflow.com/questions/49290446/creating-product-while-creating-listing

    I saw You solved similar matter. thanks

    Reply
  2. SilvanaBow@yahoo.com'

    Good, this is what I was searching for in google

    Reply
  3. castordida@hotmail.com'

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

    Reply
    • 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!

      Reply
  4. schalk@thissideup.media'

    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
    Schalk

    Reply
  5. andryldev@gmail.com'

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

    Reply
    • Hi Andry,

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

      Reply

Leave a Reply to Silvana Cancel reply

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


*