• Resolved thefrisb

    (@thefrisb)


    I use the following code to generate a shortcode to display short description, which should work for normal product description but yet it does not.
    However, it works for short description.

    add_shortcode('product_descr', 'display_product_description');
    
    function display_product_description( $atts )
    
    {
    
        $product = wc_get_product();
    
        $id = $product->get_id();
    
        extract(shortcode_atts( array(
    
            'post_id' => '$id',
    
            'short'   => '0' // '1' for short description
    
        ), $atts));
    
        $content = $short == 0 ? get_the_content(null, false, $post_id) : get_the_excerpt( $post_id );
    
        return wpautop($content);
    
    }

    The short description shows correctly with the shortcode, however for description it does not work.
    I enter the shortcode in the Elementor ShortCode widget, which i save as a global widget, and use the widget’s template shortcode, which i enter in the Elementor Toggle Widget.
    The first tab is where the description should appear.
    The second one works correctly, it gives the short description.

    How do i implement this?

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

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to generate product description shortcode’ is closed to new replies.