Created
October 30, 2023 04:39
-
-
Save SirDarcanos/2060069fd524aaf732c7dfe7432b55ca to your computer and use it in GitHub Desktop.
Hide orders 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 | |
// 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