Skip to content

Instantly share code, notes, and snippets.

@SiR-DanieL
Created October 30, 2023 04:39
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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