Skip to content

Instantly share code, notes, and snippets.

@SirDarcanos
Last active October 27, 2023 08:15
Show Gist options
  • Save SirDarcanos/fc207a6789520f699c5ebadadd5d03b7 to your computer and use it in GitHub Desktop.
Save SirDarcanos/fc207a6789520f699c5ebadadd5d03b7 to your computer and use it in GitHub Desktop.
Show Customer's Order by Email
<?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