Pull Related Products from Primary Category Only
-
I am using WooCommerce and would like to have the related products only pull products from the product’s primary category, not all categories.
I found some code to do this when using Yoast to set the primary category but can’t figure out how to do it with RankMath.
I edited the Yoast code and this is one version I tried, but it hasn’t worked.
// Alter related products query to pull items from RankMath Primary Category add_filter( 'woocommerce_get_related_product_cat_terms', function( $terms, $product_id ) { if ( function_exists( 'rank_math_primary_product_cat' ) ) { $primary_term_product_id = rank_math_primary_product_cat( 'product_cat', $product_id ); if ( $primary_term_product_id ) { return array( $primary_term_product_id ); } } return $terms; }, 10, 2 );
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Pull Related Products from Primary Category Only’ is closed to new replies.