0

I am using below function to display product information in Shop Page.

function woocommerce_template_loop_product_title() {
        echo '<h5 class="' . esc_attr( apply_filters( 'woocommerce_product_loop_title_classes', 'woocommerce-loop-product__title' ) ) . '">' . get_the_title() . ' </h5>'; 
        echo '<p>' . get_the_excerpt() . '</p>';
    }

I can fetch product shot description using get_the_excerpt(). But I would like to fetch all product information like size, price, color.

I can see below information in Product page.

enter image description here

I would like to fetch these information in Shop page with all products.

How can I fetch all product information ?

2 Answers 2

1

Product Attributes without Variation Don't Display in Shop page & Product Page

Add Attribute and Variations in Product ( Refer blog )

Note : Product variations is Used Only Variable Product.

And Then after put this code in function.php

   add_action( 'woocommerce_after_shop_loop_item_title', 'bbloomer_echo_stock_variations_loop' );

function bbloomer_echo_stock_variations_loop(){
    global $product;
    if ( $product->get_type() == 'variable' ) {
        foreach ( $product->get_available_variations() as $key ) {
            $attr_string = array();
            foreach ( $key['attributes'] as $attr_name => $attr_value ) {
                $attr_string[] = $attr_value;
                $arr_names[] = $attr_name;
            }

            $attr_color = $arr_names[0];
            $attr_size = $arr_names[1];
            $strle = 'attribute_pa_';

            $attr_name_a  = substr($attr_color, strlen($strle));
            $attr_name_a2  = substr($attr_size, strlen($strle));

           
            if ( $key['max_qty'] > 0 ) { 
              echo '<div><p>' .$attr_name_a.' : '.$attr_string[0].' , '.$attr_name_a2.' : '.$attr_string[1].' , ' . $key['max_qty'] . ' in stock</p></div>'; 
            } else { 
              echo '<div><p>' .$attr_name_a.' : '. $attr_string[0].',' .$attr_name_a2.' : '.$attr_string[1].'   out of stock</p></div>'; 
            }
        }
    }
}

Look Like Below image :

enter image description here

1
  • Thanks @HK89. I would like to show all the information not only variations. i.sstatic.net/PHASl.png Thanks.
    – abu abu
    Commented Oct 23, 2020 at 14:09
0

The Complete woocommerce Product Description add in shop page.

  add_action( 'woocommerce_after_shop_loop_item_title', 
   'wc_add_short_description' );

  function wc_add_short_description() {
    global $product;

    ?>
        <div itemprop="description">
            <?php echo apply_filters( 'woocommerce_short_description', $product->post-> post_excerpt ) ?>
        </div>
    <?php
}

This code add in function.php file

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.