Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bernattorras/a16d4e09112ddfdf507d43e5f20a3c50 to your computer and use it in GitHub Desktop.
Save bernattorras/a16d4e09112ddfdf507d43e5f20a3c50 to your computer and use it in GitHub Desktop.
Function to get all the renewal orders with a specific status of a customer
<?php
function wc_get_customer_renewal_orders_by_status($customer_id, $status) {
$args = array(
'post_type' => 'shop_order',
'post_status' => $status,
'order' => 'ASC',
'meta_query' => array(
array(
'key' => '_customer_user',
'value' => $customer_id,
'compare' => '=',
),
array(
'key' => '_subscription_renewal',
'value' => '',
'compare' => '!=',
),
),
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
return $query->posts;
}
return false;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment