Created
August 8, 2023 18:06
-
-
Save pingram3541/5d7f3f303a53a46a5d128ffa214c06de to your computer and use it in GitHub Desktop.
WooCommerce - How to check for Guest Orders
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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