WooCommerce being an eCommerce platform you will have to search for products in different ways and one of them is using SKU.

 SKU stands for Stock Keep Unit which is used to track and provide products using its SKU id.

To equip SKU search in a WooCommerce site, you will need to append ‘SKU:’ at the start of your product search followed by the product ID in your products panel of WooCommerce.

This search will return you the product whose product ID you have specified.

SKU in WooCommerce

To perform SKU search on the site programmatically,  you can use the below shown function.

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;
}

This function takes the SKU PRODUCT ID  as an argument and perform and SQL Query search with the product id you provided and return the result which is found.

SKU Product ID SQL QUERY

An Easier Way to add WooCommerce Product Search by SKU is by using WP fastest site search plugin by Expertrec

  1. Install WP fastest site search plugin from WordPress plugin store.
  2. Go to https://cse.expertrec.com/newuser?platform=wordpress.
  3. Enter your WordPress website URL and click on next->
  4. The crawl will start in the background.
  5. Login to your WordPress admin panel.
  6. In your left panel you must be able to see expertrec’s WordPress plugin, click on that.
  7. Get your site ID (or) API key from your expertrec control panel ( here ).
  8. Copy paste your site id in your WordPress control panel and click on save changes.
  9. Make sure you have upgraded to a paid plan before 15 days of free trial. (Price begins at 9 USD per month)
  10. That’s it! Your brand new WordPress search is up and running!

Add great search to your wordpress site at 9 USD per month

 

Here is more information on appending SKU to the products in a website

You may also like

Halloween sale is live! 8 Days 18 Hours 49 Minutes 53 Seconds left to get your free search!
Sign up