Search SKU and Product Title

Add the below PHP code in your function.php file or plugin file to search both the product title and the SKU in woo-commerce.

$query_withMeta_search = new WP_Query(
    array(
        "post_type" => "product",
        "s" => $search_query,
        "meta_query" => array(
                "key" => "_sku",
                "value" => $search_query,
                "compare" => "LIKE"
        )
    )
);

Leave a Reply

Your email address will not be published. Required fields are marked *