Skip to content

Instantly share code, notes, and snippets.

@SirDarcanos
Created October 30, 2023 04:39
Show Gist options
  • Save SirDarcanos/2060069fd524aaf732c7dfe7432b55ca to your computer and use it in GitHub Desktop.
Save SirDarcanos/2060069fd524aaf732c7dfe7432b55ca to your computer and use it in GitHub Desktop.
Hide orders by email
<?php
// Filter orders based on the entered email
function filter_orders_by_emails( $query ) {
global $typenow, $wpdb;
if ( 'shop_order' == $typenow && isset( $_GET['filter_emails'] ) && !empty( $_GET['filter_emails'] ) ) {
$emails = array_map('sanitize_email', explode(',', $_GET['filter_emails']));
$order_ids = $wpdb->get_col( "SELECT pm.post_id FROM {$wpdb->postmeta} pm WHERE pm.meta_key = '_billing_email' AND pm.meta_value IN ('" . join("','", $emails) . "')" );
// Adjust the main query to exclude orders with the specified email
$query->set( 'post__not_in', $order_ids );
}
}
add_action( 'pre_get_posts', 'filter_orders_by_emails' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment