Skip to content

Instantly share code, notes, and snippets.

@jchristopher
Last active February 2, 2019 15:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jchristopher/0dd86e6eee69f191e7d7335ac688a0af to your computer and use it in GitHub Desktop.
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/
<?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