I would like to mark a primary product category

#186485
  • Resolved MyNameis32
    Rank Math free

    I have a webshop, which has a several products and one product belongs to more than one category.
    I would like to choose a primary product category and after that it will only pop up the related products suggestion.

    This function is with Yoast, but we use RankMath.

    Can you help me, please?

Viewing 1 replies (of 1 total)
  • Brian
    Rank Math free

    Hello,

    Thank you for contacting Rank Math and sorry for any inconvenience that might have been caused due to that.

    Could you please try using this code for your case here:

    
    /**
     * Show related products from Primary Product Category
     */
    add_filter( 'woocommerce_get_related_product_cat_terms', function ( $terms, $product_id ) {
    
    	if ( ! empty( $primary_cats = get_post_meta( $product_id, 'rank_math_primary_product_cat' ) ) ) {
    		return $primary_cats;
    	}
    
    	return $terms;
    }, 10, 2 );

    We really look forward to helping you.

    Thank you.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 1 replies (of 1 total)

The ticket ‘I would like to mark a primary product category’ is closed to new replies.