'WooCommerce product not searchable by SKU when created by import

When importing products with CSV searching for one of the products created by the import by name works, but searching for the SKU returns nothing. This is true both in admin and the storefront (using a search plugin that can search by SKU).

The created products are also visible at the top of the product list, and it lists the SKU correctly.

If a product is updated (going into edit or quick edit and just clicking update) it is then searchable by SKU both in admin and the store.

If a product is created manually and then updated with import this is not an issue.



Solution 1:[1]

I had this same problem and I imported products with ImportWP. Admin products search would not find anything by sku, ImportWP stopped working, WooCommerce import would complain about "No matching product exists to update.". This would get fixed by switching SKU from "123" to "1234" and back to "1234" somehow refreshing indexes. I looked in the database and in the table wc_product_meta_lookup the sku field was empty for my newly imported products. I ran the following query and now updates work again.

Update
  wc_product_meta_lookup as C
  inner join (
    SELECT post_id, meta_value as sku FROM `postmeta` where meta_key = "_sku"
  ) as A on C.product_id = A.post_id
set C.sku = A.sku

This is on Wordpress 5.8.3 and WC 6.0.0 so looks like this bug can still occur.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Brother Mouzone