Phone Orders For WooCommerce

Search by ID or SKU

By default, the Phone Orders for WooCommerce plugin allows agents to search for existing products by typing the product name. This works well in many situations, but there are times when a name-based search is not enough.

Consider a customer who calls to reorder a product but cannot remember its full name. The agent may only have the product’s numeric ID or its SKU from an old invoice or order confirmation. Without the ability to search by these identifiers, the agent must manually browse the catalogue, which wastes time and frustrates the customer.

This guide explains how to modify the product search behaviour so that agents can find products instantly by entering either the product ID or the SKU. The solution uses a simple PHP code snippet that extends the built‑in search logic without changing any core plugin files.


What Problem Does This Solve?

The standard search field in the Phone Orders interface is designed to match product names. It looks at the product title and returns results that contain the typed text. This approach has two limitations:

  • Product ID search is not supported at all. If an agent enters 1234 (assuming that is the product ID), the search returns no results.
  • SKU search is not supported by default. If an agent enters SKU-1002 into the search field, the plugin treats it as a product name and will not find the item unless the product title happens to contain that exact string.

The code snippet below solves both limitations by adding an extra step to the search process. Whenever an agent types something into the product search field, the plugin first checks whether the entered text matches an existing product ID or SKU. If a match is found, that product is immediately returned as the search result – even before the standard name‑based search runs.


The Solution: Customising the Product Search Logic

The Phone Orders for WooCommerce plugin provides a dedicated filter hook for customising product search behaviour: wpo_custom_product_search. This hook allows developers to override the default search logic or add extra conditions.

The filter receives three parameters:

ParameterTypeDescription
$idsarrayThe current array of product IDs found by the default search.
$query_argsarrayThe arguments that would be passed to the product query.
$termstringThe search term entered by the agent.

The custom function attached to this filter examines the search term ($term). It checks whether the term corresponds to a valid product ID or SKU. If a match is found, the function returns an array containing the single product ID, effectively replacing the default search results. If no match is found, the function returns false, which tells the plugin to fall back to the standard name‑based search.

 Choose where to add the code

You have two reliable options for adding custom PHP code:

Option A (Recommended): Use a code snippet plugin. The free Code Snippets plugin (available at wordpress.org) is the safest method. It allows you to add, activate, and deactivate code snippets without ever touching your theme files.

Option B: Add to your child theme’s functions.php file. If you are already comfortable editing theme files, add the code to your active child theme’s functions.php file. Never add custom code directly to a parent theme, because it will be lost when the theme is updated.

Have questions? Please submit a support request. We're always happy to help!

Phone Orders
for WooCommerce
PRO

From $120
Buy
✓ 30-day money-back guarantee