Skip to content

Instantly share code, notes, and snippets.

@danielbitzer
Created January 23, 2018 14:48
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielbitzer/d33a993b269729751f89c2e385de534d to your computer and use it in GitHub Desktop.
Save danielbitzer/d33a993b269729751f89c2e385de534d to your computer and use it in GitHub Desktop.
AutomateWoo - Get a list of a user's generated coupons
<?php
// please note the _aw_customer_id meta data was added in version 3.5.1
$user_id = 123; //example id
$customer = AutomateWoo\Customer_Factory::get_by_user_id( $user_id );
$query_args = [
'post_type' => 'shop_coupon',
'posts_per_page' => -1,
'orderby' => 'date',
'order' => 'ASC',
'meta_query' => [
[
'key' => '_is_aw_coupon',
'value' => true
],
[
'key' => '_aw_customer_id',
'value' => $customer->get_id()
]
]
];
$query = new \WP_Query( $query_args );
$coupons = $query->posts;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment