How to Find Product by SKU in WooCommerce

Searching the Admin
You can search for a product by SKU in the admin Products list page by starting the search string with the special “SKU:” indicator. So for instance, if the product you are searching for has a SKU of ’4′, your search string would look like: “SKU:4″. Here’s an example:
Programmatically
Here’s a little snippet of code which you can use in your WooCommerce plugin development to get a particular product by its SKU. Enjoy:
function get_product_by_sku( $sku ) {
global $wpdb;
$product_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_sku' AND meta_value='%s' LIMIT 1", $sku ) );
if ( $product_id ) return new WC_Product( $product_id );
return null;
}

Can this be added to some woocommerce code (without a plugin)? If so which file?
Hey, this is really meant to be used when developing a plugin where you need to look up a product by SKU. Are you looking for a way for customers to be able to use the site search box to find a product by SKU?
I am looking for a way for customers to be able to use the site search box to find a product by SKU. Can you please help. Thanks in advance
I am looking for a way for customers to be able to use the site search box to find a product by SKU. Can you please help. Thanks in advance
Yeah, that would be a handy feature. Not sure how to do it, but it’s something I’m going to try and look into at some point
Hi, Thank you for your info. Which file should I add these code in? Please let me know. Thanks.
Hey Opal, this code snippet doesn’t do anything on its own; it’s really just meant to be a little timesaver for WooCommerce developers.
I found a plugin that claims to allow customers to search products using SKU… I haven’t tried it yet.
http://ignitewoo.com/woocommerce-extensions-plugins/woocommerce-live-search-title-description-excerpt-category-tag-keywork-sku/
I am actually looking for a plugin that allows site manager to search by SKU
What do you mean by allowing a site manager to search by SKU? Search where?
In the product backend… wordpress admin area. I have a client who wants to search for products by SKU.
Yeah, it’s a little weird, but you actually use something like the following when searching in the admin: “SKU:406″ assuming here that the product SKU you want is, or contains “406″
Justin, thank you! That is very helpful. The only issue is that it seems to be a little quirky. Some SKU’s that I know exist, aren’t pulling up with the search :-/
Hmm, weird, it seemed to work fine for me in my couple of test cases, but who knows, perhaps there’s some bug with it
Hi Justin,
Nice information here, thanks! Is it possible to also search on other fields in the woocommerce product admin or does this only work for SKU? I would love to be able to search on more fields (like Price) with this method?
Hey John, actually you’re the second person to ask me this recently, so I wrote up a quick post on searching for WooCommerce orders by custom fields. Hope this helps!