Last active
February 2, 2019 15:09
-
-
Save jchristopher/0dd86e6eee69f191e7d7335ac688a0af to your computer and use it in GitHub Desktop.
Use a supplemental engine when searching WooCommerce Orders. See https://searchwp.com/docs/kb/searching-woocommerce-orders/
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 | |
/** | |
* When performing an admin search for WooCommerce Orders, use the 'Orders' SearchWP engine | |
*/ | |
function my_searchwp_search_args( $args ) { | |
$search_in_admin = apply_filters( 'searchwp_in_admin', false ); | |
if ( wp_doing_ajax() || empty( $_GET['post_type'] ) || ! is_admin() || empty( $search_in_admin ) ) { | |
return $args; | |
} | |
if ( 'shop_order' !== $_GET['post_type'] ) { | |
return $args; | |
} | |
// WooCommerce adds some limiting that we're going to get rid of here | |
add_filter( 'searchwp_include', function( $ids ){ | |
return is_admin() && is_search() ? array() : $ids; | |
}, 999 ); | |
$args['engine'] = 'orders'; | |
return $args; | |
} | |
add_filter( 'searchwp_search_args', 'my_searchwp_search_args' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment