Relevanssi Woocommerce article number boost

How to highlight the article in Relevanssi when searching for an article number.

I once had the case that my customer has put a lot of emphasis on the fact that you should also search for products with their article numbers in his shop. This means that you can simply enter an article number into the search.

The problem with Relevanssi, however, is that you can type the SKU as a custom search box, but you can not set the score.

However, Relevanssi provides the ability to programmatically set the scoring. You can thus match the search term with the article number and adjust the rating as desired. I solved that as follows

add_filter( 'relevanssi_match', 'rlv_woo_sku_match' );
function rlv_woo_sku_match( $match ) {
	global $query;
    if ( strtoupper(get_post_meta($match->doc, '_sku', true)) == strtoupper($query->query['s']) ) $match->weight *= 10;
    return $match;


php Polylang Relevanssi WooCommerce WordPress

Beitrag teilen

WhatsApp it

Folgen Sie uns