Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #890885
    CodetrixNZ
    Participant

    Hi Team,
    I’m not exactly sure how to describe this, so in the next post I’ll supply login details for our development site and attach a screenshot.
    We wanting to add the products category between the product title and the product price, when your viewing products in list view/shop page etc.

    We’re using the renew stack, but looking across the different stacks available, it doesn’t appear any of them do this.
    Thank you!

    #890888
    CodetrixNZ
    Participant
    This reply has been marked as private.
    #891574
    Zeshan
    Member

    Hi Aaron,

    Thanks for writing in!

    Product categories only appear under single product page. It could be possible to add them in the main shop page with custom development. While that is outside the scope of support, I could point you in the right direction with the understanding that it would ultimately be your responsibility to take it from here.

    Because this requires a template change, I’d advise that you setup a child theme. This allows you to make code changes that won’t be overwritten when an X update is released. After your child theme is setup, please review how we recommend making template changes in Customization Best Practices.

    After that, add following code in your child theme’s functions.php file:

    // Add Category in Between Product Title and Price
    // =============================================================================
    
    function category_after_shop_loop_item_title() {
      $categories        = get_the_terms( get_the_ID(), 'product_cat' );
      $separator         = ', ';
      $categories_output = '';
      if ( ! empty( $categories ) ) {
        foreach ( $categories as $category ) {
          $categories_output .= '<a href="'
                              . get_term_link( $category->slug, 'product_cat' )
                              . '" title="'
                              . esc_attr( sprintf( __( "View all posts in: &ldquo;%s&rdquo;", '__x__' ), $category->name ) )
                              . '">'
                              . $category->name
                              . '</a>'
                              . $separator;
        }
      }
    
      $categories_list = sprintf( '<span class="product-categories">%s</span>',
        trim( $categories_output, $separator )
      );
    
      echo $categories_list;
    }
    
    add_action( 'woocommerce_after_shop_loop_item_title', 'category_after_shop_loop_item_title', 9 );
    

    Hope this helps. 🙂

    Thank you!

    #892543
    CodetrixNZ
    Participant

    ….You know you guys are legends right?!
    Most support teams would just say go away and ask else where.
    THIS is a big reason why we will continue to support this theme & team. Thank you, your time, its very much appreciated.

    #893312
    Lely
    Moderator

    You’re welcome!

    Cheers!

  • <script> jQuery(function($){ $("#no-reply-890885 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>