WooCommerce: Alter Product Search @ Manual Admin Orders

Ok, we’re in a niche of a niche this time – manual orders (orders created by the WooCommerce administrator). If you’re familiar with that, the admin would click on “Add order“, fill out the billing & shipping information, and then move to the order items section, where they can add products to the order.

As soon as they click on “Add items” > “Add products“, a table displays with a product search and quantity input. That’s exactly where we’re working today: what if you have 10,000 products in your store, but only create manual invoices with the same 2-3 products? In this case scenario, it makes no sense to search for the whole 10,000 product list and wait for WooCommerce to return a result (slowly) – it’s much more efficient to reduce that list to a specific category or a list of IDs so that the search operations can be faster.

Here’s how it’s done. Enjoy!

With the snippet below, I’ve reduced the possible search results to… 2 products only, by simply defining an array of product IDs.

PHP Snippet: Alter Product Search @ WooCommerce Order Admin

/**
 * @snippet       Only Search Array of Product IDs @ Order Admin
 * @how-to        businessbloomer.com/woocommerce-customization
 * @author        Rodolfo Melogli, Business Bloomer
 * @testedwith    WooCommerce 6
 * @community     https://businessbloomer.com/club/
 */

add_filter( 'woocommerce_product_pre_search_products', 'bbloomer_only_search_these_products', 9999, 6 );

function bbloomer_only_search_these_products( $custom_query, $term, $type, $include_variations, $all_statuses, $limit ) {
	if ( ! isset( $_GET['exclude_type'] ) ) return $custom_query; 
	// we should be on the order admin page now	
	$product_ids = array( 21230, 21231 );
	return $product_ids;
}

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

Your email address will not be published. Required fields are marked *