title: Automatically remove used coupons
body: <p>I've found the code for doing something similar but I can't make it to work for used coupons, I need something like &quot;if coupon usage is 1/1&quot; then delete it.</p>
  <p>Code i've used from <a href="https://nicolamustone.blog/2018/08/01/delete-expired-coupons-automatically" rel="nofollow noreferrer">https://nicolamustone.blog/2018/08/01/delete-expired-coupons-automatically</a></p>
  <pre><code> * Schedule the daily event if necessary.
   */
  function schedule_delete_expired_coupons() {
      if ( ! wp_next_scheduled( 'delete_expired_coupons' ) ) {
          wp_schedule_event( time(), 'daily', 'delete_expired_coupons' );
      }
  }
  add_action( 'init', 'schedule_delete_expired_coupons' );
  
  /**
   * Trash all expired coupons when the event is triggered.
   */
  function delete_expired_coupons() {
      $args = array(
          'posts_per_page' =&gt; -1,
          'post_type'      =&gt; 'shop_coupon',
          'post_status'    =&gt; 'publish',
          'meta_query'     =&gt; array(
              'relation'   =&gt; 'AND',
              array(
                  'key'     =&gt; 'date_expires',
                  'value'   =&gt; current_time( 'timestamp' ),
                  'compare' =&gt; '&lt;='
              ),
              array(
                  'key'     =&gt; 'date_expires',
                  'value'   =&gt; '',
                  'compare' =&gt; '!='
              )
          )
      );
  
      $coupons = get_posts( $args );
  
      if ( ! empty( $coupons ) ) {
          foreach ( $coupons as $coupon ) {
              wp_trash_post( $coupon-&gt;ID );
          }
      }
  }
  add_action( 'delete_expired_coupons', 'delete_expired_coupons' );``` 
  </code></pre>