• Resolved plokamias

    (@plokamias)


    Hello there guys,

    Is there a way to change the weight / priority given to specific woocommerce product categories?

    In my case, when someone is searching for a printer, the inks and peripherals of the printer (different products from different categories) appear first and we wish for the main product to get the highest weight / priority.

    Thank you in advance for your reply.

    Best regards,

    Victor

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Mikko Saari

    (@msaari)

    Yes, you can give specific categories boost using the relevanssi_match filter hook. See “Weight from taxonomy terms” here: https://www.relevanssi.com/knowledge-base/relevanssi-match/#taxonomyterms

    Thread Starter plokamias

    (@plokamias)

    Hello there Mikko and thank you very much for your reply,

    So, if I understand correctly, in case I wish that the products included in the product category “123” get a higher weight than the other products in all the other categories having weight 5, I need the function to look like this:

    add_filter( ‘relevanssi_match’, ‘rlv_boost_one_term’ );
    function rlv_boost_one_term( $match ) {
    if ( has_term( ‘123’, ‘product_cat’, $match->doc ) ) {
    $match->weight *= 6;
    }
    return $match;
    }

    I have tried to add that function to my functions.php, but unfortunately it won’t work.

    Can it be that the actual category slug contains greek characters or is there something I understood wrong and I need to correct on the php?

    Thank you in advance for your reply!

    Best regards,

    Victor

    Plugin Author Mikko Saari

    (@msaari)

    If you want to use the category ID, use a number, ie. has_term( 123, 'product_cat', $match->doc ). If you use a string, '123', it is consider a category name or slug.

    Thread Starter plokamias

    (@plokamias)

    Hello there again Mikko and thank you for the reply.

    I am sorry that I can’t get this right. So, I want the products included in the category xerox-εκτυπωτ?? (that is the slug of the category) to get a priority in the search results.

    Here is the code I use and does not work:

    add_filter( 'relevanssi_match', 'rlv_boost_one_term' );
    function rlv_boost_one_term( $match ) {
    	if ( has_term( 'xerox-εκτυπωτ??', 'product_cat', $match->doc ) ) {
    		$match->weight *= 6;
    		}	
    	return $match;
    }

    What needs to be changed in the code, for the products included in that category to get priority listing in the search results?

    Thank you in advance for your reply.

    Best regards,

    Victor

    Plugin Author Mikko Saari

    (@msaari)

    That looks right to me, so I would try debugging that. Is the function running in the first place? Does the has_term() work? If you put an echo "product has term"; inside the has_term() conditional and do a search, does that work when you do the search?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Weight per product category’ is closed to new replies.