Display Primary product category in woocomerce single product

#266893
  • Resolved Jorge Lima
    Rank Math free

    Hello,i’m moving from yoast to page rankand in woocommerce single product i use this code to get product primary category, can you help me to do the same on RankMath.


    $primary_term_product_id = _yoast_get_primary_term_id('product_cat');
    $postProductTerm = get_term( $primary_term_product_id );

    //If the post type is a product, display the Primary Category Link
    if ( 'product' === get_post_type() ) { ?>
    <div class="primary-cat">
    <?php
    if ( $postProductTerm && ! is_wp_error( $postProductTerm ) ) {
    //echo 'term_id ) ) . '">';
    echo $postProductTerm->name;
    echo '
    ';
    }
    ?>
    </div><?php
    }

    Thanks in advance,

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello,

    Thank you for contacting Rank Math today.

    Could you please try changing the variable primary_term_product_id to the following?

    
    $primary_term_product_id = get_post_meta(get_queried_object_id(), 'rank_math_primary_product_cat', true);
    

    ​​​​​​Let us know if this helps solve your issues.

    Thats it, thanks!

    Azib Yaqoob
    Rank Math business

    Hello,

    We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this ticket.