• Resolved geronimo108

    (@geronimo108)


    Hello to everyone,

    I need your help to show category, label and description for each products on Shop Page, just below a title of a product.
    I made my website with DIVI and I wrote them for ask them some help ! This is what they replied : “You right, our builder is not building the product elements, that is how the Woo shortcode is showing them, and we just use that.
    However, there could be a way to do this via a PHP code, please refer to Woocommerce support for help ?? ”

    This topic was maybe already answered but I didn’t find it (thnaks to the search bar of www.ads-software.com ^^) Can you please help me ?

    You can access to my shop page : https://arte-politeia.arcadesigner.com/catalogue/

    Thank you in advance !

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support kellymetal a11n

    (@kellymetal)

    Hi there,

    I understand you are trying to add some extra information for each of your products on the shop page. I’m not entirely sure what you mean by “label”, but the following will add the first Category and the product description below the product name/title:

    
    // Add category and description to products in shop
    if ( ! function_exists( 'my_shop_product_custom_display' ) ) {
        function my_shop_product_custom_display() {
            global $product;
            $categories = $product->get_category_ids();
            if(! empty($categories)){
                $term = get_term_by( 'id', $categories[0], 'product_cat' )
                ?>
                <h2 class="woocommerce-loop-product__category">
                    <?php
                    echo esc_html( $term->name );
                    ?>
                </h2>
                <?php
            }
            ?>
            <h2 class="woocommerce-loop-product__description">
                <?php
                echo esc_html( $product->get_description() );
                ?>
            </h2>
            <?php
        }
    }
    add_action( 'woocommerce_shop_loop_item_title', 'my_shop_product_custom_display', 20 );
    

    That code should be added to your child theme’s functions.php file or via a plugin that allows custom functions to be added, such as the Code Snippets ( https://www.ads-software.com/plugins/code-snippets/ ) plugin. Please don’t add custom code directly to your parent theme’s functions.php file as this will be wiped entirely when you update.

    Hopefully that can get you started with what you are trying to do.

    If you need further assistance with coding or custom development, we recommend reaching out to a developer from one of the services at https://woocommerce.com/customizations/.

    Have a good one!

    Thread Starter geronimo108

    (@geronimo108)

    Thank you very much for taking the time to help me !!

    Impressive!

    I just found a code this morning to help me do this and I’m sharing it in case anyone is interested.

    function wpa89819_wc_single_product(){
        $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 ); ?>
            <h3 itemprop="name" class="product_category_title" style="font-size:20px"><span><?php echo $single_cat->name; ?></span></h3>
    <?php }
    }
    add_action( 'woocommerce_after_shop_loop_item_title', 'wpa89819_wc_single_product', 2 );

    I didn’t konw about child theme so thank you also about that !

    Take care ??

    Plugin Support kellymetal a11n

    (@kellymetal)

    Hi there @geronimo108,

    Thank you very much for sharing your findings as well!

    And I’m glad to hear the info about the child theme was helpful. : )

    I’m going to mark this thread as resolved. If you have any further questions, please start a new thread.

    Have a wonderful day!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Show category, label, description on Shop Page’ is closed to new replies.