Categories above the product name - by youkila

This topic has 6 replies, 2 voices, and was last updated 3 years, 2 months ago ago by Olga Barlow

  • Avatar: youkila
    youkila
    Participant
    October 18, 2021 at 11:48

    Hi again,
    Another question, I’d like to show Categories above the product name in single product page. And I want to change the colors.
    How can I manage it?

    Thank you,
    Youkila

    5 Answers
    Avatar: Olga Barlow
    Olga Barlow
    Support staff
    October 18, 2021 at 17:19

    Hello,

    Do you use a built-in single product layout or a single product builder?

    Regards

    Avatar: youkila
    youkila
    Participant
    October 18, 2021 at 19:07

    Hi Olga Barlow,
    Thank you for contacting me.
    I’m using a built-in single product layout.

    Best,
    Youkila

    Avatar: Olga Barlow
    Olga Barlow
    Support staff
    October 18, 2021 at 19:44

    Hello,

    There is no such option. But you may try to use WooCommerce hooks to implement this by additional customization.
    For example, add the below code to child theme functions.php

    function custom_single_product_category(){
        $product_cats = wp_get_post_terms( get_the_ID(), 'product_cat' );
        if ( $product_cats && ! is_wp_error ( $product_cats ) ){
            $single_cat = array_shift( $product_cats ); ?>
            <h2 itemprop="name" class="product_category_title"><span><?php echo $single_cat->name; ?></span></h2>
    <?php }
    }
    add_action( 'woocommerce_single_product_summary', 'custom_single_product_category', 2 );

    Regards

    Avatar: youkila
    youkila
    Participant
    October 18, 2021 at 20:01

    Hi Olga Barlow,
    Thank you for your reply.
    It works but display only one category.
    Actually each products has several categories in my site.
    Is it possible to show every categories as meta field?

    Thank you very much in advance.
    Youkila

    Avatar: Olga Barlow
    Olga Barlow
    Support staff
    October 20, 2021 at 08:51

    Hello,

    Then replace the previous code by this one
    add_action( 'woocommerce_single_product_summary', 'etheme_product_cats', 2 );
    And don’t choose Primary category in the single product settings https://prnt.sc/1wtkawh

    Regards

  • Viewing 6 results - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.Log in/Sign up

We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.