skip to Main Content

I added gallery code to description.php, but if my product description is empty, this tab is hidden.
If the product description is not empty, the newly added ACF gallery will also be displayed normally at the same time.

How can I modify the forced display of the product description tab?

thank you

2

Answers


  1. Chosen as BEST ANSWER

    I created a tag myself to solve this problem

    //  商品TABS  商品介紹
    add_filter( 'woocommerce_product_tabs', 'misha_custom_tab' );
    function misha_custom_tab( $tabs ) {
        $tabs['misha_custom_tab'] = array(
            'title'    => '商品介紹',
            'callback' => 'misha_custom_tab_content', // the function name, which is on line 15
            'priority' => 1,
        );
        return $tabs;
    }
    function misha_custom_tab_content( $slug, $tab ) {
        echo the_field( 'product_ddescription' );
        echo callACF();
    }
    function callACF()
    {
        
        $product_introduction_image_images = get_field( 'product_introduction_image' ); 
        $str = '';
        if ( $product_introduction_image_images ) {
            foreach ( $product_introduction_image_images as $product_introduction_image_image ) {
                $str .= '<img src="'.esc_url( $product_introduction_image_image['url'] ).'" alt="'.esc_attr( $product_introduction_image_image['alt'] ).'" />';
            }
        
        }
        return $str;
    }


  2. Since you’re using ACF and you’ve got your own description.php file, one simple answer is just to put the words "Hello World!" (or anything) in the product description editor area. It will never show because you’ve overriden the description tab content.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search