Last active
October 27, 2023 08:15
-
-
Save SirDarcanos/fc207a6789520f699c5ebadadd5d03b7 to your computer and use it in GitHub Desktop.
Show Customer's Order by Email
This file contains hidden or 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
<?php | |
function show_specific_customer_orders($query) { | |
global $pagenow, $typenow; | |
if (!is_admin() || !$query->is_main_query() || 'shop_order' !== $typenow || 'edit.php' !== $pagenow || !isset($_GET['filter_email']) || empty($_GET['filter_email'])) { | |
return; | |
} | |
$email_to_filter = sanitize_email($_GET['filter_email']); | |
$customer_orders = wc_get_orders(array('limit' => -1, 'customer' => $email_to_filter, 'return' => 'ids')); | |
if (!empty($customer_orders)) { | |
$query->set('post__in', $customer_orders); | |
} else { | |
$query->set('post__in', array(0)); | |
} | |
} | |
add_action('pre_get_posts', 'show_specific_customer_orders'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment