Skip to content

Instantly share code, notes, and snippets.

@pingram3541
Created August 8, 2023 18:06
Show Gist options
  • Save pingram3541/5d7f3f303a53a46a5d128ffa214c06de to your computer and use it in GitHub Desktop.
Save pingram3541/5d7f3f303a53a46a5d128ffa214c06de to your computer and use it in GitHub Desktop.
WooCommerce - How to check for Guest Orders
//set the email address
$email = 'your@ema.il';
//get orders using the customer email address
$query = new WC_Order_Query();
$query->set( 'customer', $email );
$query->set( 'limit', -1 );
$orders = $query->get_orders();
//check if not a WordPress user but orders do exist
$wp_user = get_user_by( 'email', $email );
$guest_orders = [];
if( empty( $wp_user ) && ! empty( $orders ) ){
//we are a guest user
foreach ( $orders as $order ) {
$status = $order->get_status();
if ( $status = 'completed' ) {
$guest_orders[] = [$order->get_id() => $order->get_status()];
}
}
}
//let's see the results
print_r( $guest_orders );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment