This file contains 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 | |
// Predefined email address | |
define('HIDDEN_EMAIL_ORDERS', 'email@tohide.com'); | |
// Add the checkbox | |
function add_email_filter_checkbox() { | |
global $typenow; | |
if ( 'shop_order' == $typenow ) { | |
$is_checked = isset( $_GET['hide_specific_email'] ) ? 'checked' : ''; | |
echo '<label style="margin-right:10px;margin-left:10px;"><input style="height:1rem;" type="checkbox" name="hide_specific_email" value="1" ' . $is_checked . '> Hide orders from ' . HIDDEN_EMAIL_ORDERS . '</label>'; | |
} | |
} | |
add_action( 'restrict_manage_posts', 'add_email_filter_checkbox' ); | |
// Filter orders based on the checkbox value | |
function filter_orders_by_checkbox( $query ) { | |
global $typenow, $wpdb; | |
if ( 'shop_order' == $typenow && isset( $_GET['hide_specific_email'] ) && '1' == $_GET['hide_specific_email'] ) { | |
$order_ids = $wpdb->get_col( $wpdb->prepare( | |
"SELECT pm.post_id FROM {$wpdb->postmeta} pm WHERE pm.meta_key = '_billing_email' AND pm.meta_value = %s", | |
HIDDEN_EMAIL_ORDERS | |
) ); | |
// 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_checkbox' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment