H
H
hooli-gun2021-09-06 12:33:46
css
hooli-gun, 2021-09-06 12:33:46

Is it possible to hide tabs if the fields are empty?

I made tabs for products using Advanced Custom Fields, in some products there are no filled in tab data, and so that they just don’t hang empty, can I make it so that if the field is not filled in, and the tab is not displayed?

<div class="woocommerce-product__tabs woocommerce-tabs wc-tabs-wrapper tabs container">
        <div class="woocommerce-product__tabs-links">
            <div class="woocommerce-product__tab product-tab__active"><?php pll_e('Характеристики'); ?></div>
            <div class="woocommerce-product__tab"><?php pll_e('Комплектація'); ?></div>
            <div class="woocommerce-product__tab"><?php pll_e('Огляд'); ?></div>
            <div class="woocommerce-product__tab"><?php pll_e('Рецепти'); ?></div>
            <div class="woocommerce-product__tab"><?php pll_e('Залишити відгук'); ?></div>
        </div>
        <div class="woocommerce-product__tabs-wrapper">
            <div class="woocommerce-product__tab-item">
                <ul class="woocommerce-product__characteristics">
                    <?php if ( have_rows( 'characteristics' ) ) : ?>
                    	<?php while ( have_rows( 'characteristics' ) ) : the_row(); ?>
                    		<li>
                    		    <span class="woocommerce-product__characteristics-name"><?php the_sub_field( 'characteristics-name' ); ?></span>
                    		    <span class="woocommerce-product__characteristics-value"><?php the_sub_field( 'characteristics-value' ); ?></span>
                    		</li>
                    	<?php endwhile; ?>
                    <?php else : ?>
                    	<?php // no rows found ?>
                    <?php endif; ?>
                </ul>
            </div>
            <div class="woocommerce-product__tab-item">
                <ol class="woocommerce-product__complete_set">
                    <?php if ( have_rows( 'complete_set' ) ) : ?>
                    	<?php while ( have_rows( 'complete_set' ) ) : the_row(); ?>
                    		<li><?php the_sub_field( 'complete_set_item' ); ?></li>
                    	<?php endwhile; ?>
                    <?php else : ?>
                    	<?php // no rows found ?>
                    <?php endif; ?>
                </ol>
            </div>
            <div class="woocommerce-product__tab-item woocommerce-product__review"><?php the_field( 'review' ); ?></div>
            <div class="woocommerce-product__tab-item">
                <div class="recipes-container">
    				<?php
    				$args = array( 'post_type' => 'recipes', 'posts_per_page' => 6 );
    				$the_query = new WP_Query( $args );
    				?>
    				<?php if ( $the_query->have_posts() ) : ?>
    				<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    
    				<article class="recipes-item">
    					<div class="recipes-img">
    						<?php echo get_the_post_thumbnail( $page->ID, 'full'); ?>
    					</div>
    					<div class="recipes-title">
    						<h3><?php the_title(); ?></h3>
    					</div>
    					<p class="recipes-category"><?php echo get_the_category(); ?></p>
    					<a href="<?php echo get_permalink(); ?>" class="recipes-link"></a>
    				</article>
    
    				<?php endwhile; ?>
    
    				<?php wp_reset_postdata(); ?>
    
    				<?php else: ?>
    
    				<?php endif; ?>
    			</div>
            </div>
            <?php foreach ( $product_tabs as $key => $product_tab ) : ?>
                <div class="woocommerce-product__tab-item woocommerce-Tabs-panel woocommerce-Tabs-panel--<?php echo esc_attr( $key ); ?> panel entry-content wc-tab" id="tab-<?php echo esc_attr( $key ); ?>" role="tabpanel" aria-labelledby="tab-title-<?php echo esc_attr( $key ); ?>">
                    <?php
                    if ( isset( $product_tab['callback'] ) ) {
                        call_user_func( $product_tab['callback'], $key, $product_tab );
                    }
                    ?>
                </div>
            <?php endforeach; ?>
        </div>
    
        <?php do_action( 'woocommerce_product_after_tabs' ); ?>
    </div>

Whatever it was
6135e07410edc347488690.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question