Tagged: SKU, woocommerce
Hi
Could you let me know how to add the Woocommerce SKU to the standard Enfold search please? It searches product titles OK so if there’s a way to configure it to have this functionality as well that would be great. There doesn’t seem to be a definitive answer on this forum or elsewhere.
Thanks in advance for your assistance.
Hey!
Please try adding following code to Functions.php file in Appearance > Editor
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;
}
Best regards,
Yigit
Hi Yigit
Thanks for the code which I added to my child theme functions file – but it doesn’t work for me :(
The search works fine for product title or description though. Have you any further thoughts?
Thanks again for your help.
Hi,
I am not sure if this plugin would work but you can try one similar to this one – https://wordpress.org/plugins/search-by-sku-for-woocommerce/
Also, please feel free to contact WooCommerce team :)
Best regards,
Yigit
Hey Yigit
Thanks – I had already tried that plugin. I will head over to the Woocommerce team to see if they can assist any further.
Again, your support is much appreciated.