Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 10 of 10
Like Tree2Likes
  • 1 Post By brandMatt
  • 1 Post By lew1s

Thread: Hide Tab when content is empty

  1. #1
    Member lew1s's Avatar
    Join Date
    Oct 2013
    Posts
    65
    Member #
    37371
    Liked
    2 times

    Hide Tab when content is empty

    how to hide tab (custom field in wordpress) when content is empty.

    you can see here on product page at bottom are 4 tabs. thanks

    ADPRO IntrusionTrace Plus - RSPL

  2.  

  3. #2
    Senior Member brandMatt's Avatar
    Join Date
    Oct 2015
    Location
    St .Catharines Ontario
    Posts
    240
    Member #
    52164
    Liked
    51 times
    I do this all the time, here is a sample block of code. '_dogs' is the custom field key name. Here's a tip, throw an underscore '_' in-front of the key to have it hidden in the admin section
    Code:
    <ul>
    
    <?php $dogs = get_post_meta(get_the_ID(),  "_dogs", true); ?>
    
    <?php if ($dogs != "" || $dogs != NULL) { ?>
    
    	<li><?php echo $dogs; ?></li>
    
    <?php } ?>
    
    </ul>
    Hope it helps.
    Last edited by brandMatt; Nov 26th, 2015 at 10:29 AM.

    My Web Site:
    brandwebdesign.ca
    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link. Some of us are really insecure and need those likes so that we feel important and smart, so come on, help us out, huh?

  4. #3
    Member lew1s's Avatar
    Join Date
    Oct 2013
    Posts
    65
    Member #
    37371
    Liked
    2 times
    actually this is my code. can you help how to do it here ? thanks

    $tabs = apply_filters( 'woocommerce_product_tabs', array() );

    if ( ! empty( $tabs ) ) : ?>

    <div class="woocommerce-tabs">
    <ul class="tabs">


    <li class="specs_tab">
    <a href="#specs-video">Specifications</a>
    </li>
    <li class="downloads_tab">
    <a href="#tab-downloads">Downloads</a>
    </li>
    <li class="video_tab">
    <a href="#tab-video">Videos</a>
    </li>


    <?php foreach ( $tabs as $key => $tab ) : ?>

    <li class="<?php echo $key ?>_tab">
    <a href="#tab-<?php echo $key ?>"><?php echo apply_filters( 'woocommerce_product_' . $key . '_tab_title', $tab['title'], $key ) ?></a>
    </li>

    <?php endforeach; ?>
    </ul>
    <?php foreach ( $tabs as $key => $tab ) : ?>

    <div class="panel entry-content" id="tab-<?php echo $key ?>">
    <?php call_user_func( $tab['callback'], $key, $tab ) ?>
    </div>

    <?php endforeach; ?>
    <div class="panel entry-content" id="tab-downloads">
    <?php echo get_post_meta(get_the_ID(), 'Downloads', TRUE); ?>
    </div>
    <div class="panel entry-content" id="tab-video">
    <?php echo get_post_meta(get_the_ID(), 'Videos', TRUE); ?>
    </div>
    <div class="panel entry-content" id="specs-video">
    <?php echo get_post_meta(get_the_ID(), 'Specifications', TRUE); ?>
    </div>
    </div>

    <?php endif; ?>

  5. #4
    Senior Member brandMatt's Avatar
    Join Date
    Oct 2015
    Location
    St .Catharines Ontario
    Posts
    240
    Member #
    52164
    Liked
    51 times
    Here's a sample, very simple stuff.
    Code:
    <?php $metaValue =  get_post_meta(get_the_ID(), 'Downloads', TRUE); ?>
    <?php if ($metaValue != "" || $metaValue != NULL) { ?>
    	<div class="panel entry-content" id="tab-downloads">
    		<?php echo $metaValue; ?>
    	</div>
    <?php endif; ?>

    My Web Site:
    brandwebdesign.ca
    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link. Some of us are really insecure and need those likes so that we feel important and smart, so come on, help us out, huh?

  6. #5
    Member lew1s's Avatar
    Join Date
    Oct 2013
    Posts
    65
    Member #
    37371
    Liked
    2 times
    matt thanks for help, but still doesnt work. got it like this.

    <?php foreach ( $tabs as $key => $tab ) : ?>

    <div class="panel entry-content" id="tab-<?php echo $key ?>">
    <?php call_user_func( $tab['callback'], $key, $tab ) ?>
    </div>

    <?php endforeach; ?>
    <div class="panel entry-content" id="tab-downloads">
    <?php echo get_post_meta(get_the_ID(), 'Downloads', TRUE); ?>
    </div>
    <div class="panel entry-content" id="tab-video">
    <?php echo get_post_meta(get_the_ID(), 'Videos', TRUE); ?>
    </div>
    <div class="panel entry-content" id="specs-video">
    <?php echo get_post_meta(get_the_ID(), 'Specifications', TRUE); ?>
    </div>
    </div>

    <?php endif; ?>

  7. #6
    Member lew1s's Avatar
    Join Date
    Oct 2013
    Posts
    65
    Member #
    37371
    Liked
    2 times
    <?php $metaValue = get_post_meta(get_the_ID(), 'Specifications', TRUE); ?>
    <?php if ($metaValue != "" || $metaValue != NULL) { ?>
    <div class="panel entry-content" id="specs-video">
    <?php echo $metaValue; ?>
    </div>
    <?php endif; ?>

    getting error:

    Parse error: syntax error, unexpected 'endif' (T_ENDIF)

  8. #7
    Senior Member brandMatt's Avatar
    Join Date
    Oct 2015
    Location
    St .Catharines Ontario
    Posts
    240
    Member #
    52164
    Liked
    51 times
    Change the endif; to }
    I mixed up my if syntax.
    The code would be
    <?php $metaValue = get_post_meta(get_the_ID(), 'Specifications', TRUE); ?>
    <?php if ($metaValue != "" || $metaValue != NULL) { ?>
    <div class="panel entry-content" id="specs-video">
    <?php echo $metaValue; ?>
    </div>
    <?php } ?>

  9. #8
    Member lew1s's Avatar
    Join Date
    Oct 2013
    Posts
    65
    Member #
    37371
    Liked
    2 times
    sorry matt, but still not working. the empty tab is still there

    <?php $metaValue = get_post_meta(get_the_ID(), 'Specifications', TRUE); ?>
    <?php if ($metaValue != "" || $metaValue != NULL) { ?>
    <div class="panel entry-content" id="specs-video">
    <?php echo $metaValue; ?>
    </div>
    <?php } ?>

    example here : Nice Moonbus - RSPL

  10. #9
    Senior Member brandMatt's Avatar
    Join Date
    Oct 2015
    Location
    St .Catharines Ontario
    Posts
    240
    Member #
    52164
    Liked
    51 times
    Sorry, the code that I gave only hid the panels, not the tabs too. I apologize.
    The code below should hide both, the tabs and the panels. Keep in mind I haven't tested it, and can't really without your database.

    Code:
    <?php $tabs = apply_filters('woocommerce_product_tabs', array()); ?>
    <?php $downloadMeta = get_post_meta(get_the_ID(), 'Downloads', TRUE); ?>
    <?php $videoMeta = get_post_meta(get_the_ID(), 'Videos', TRUE); ?>
    <?php $specMeta =  get_post_meta(get_the_ID(), 'Specifications', TRUE); ?>
    <? if (!empty($tabs)): ?>
    
        <div class = "woocommerce-tabs" >
            <ul class = "tabs" >
                <?php if ($specMeta != "" || $specMeta != NULL) : ?>
                    <li class = "specs_tab" >
                        <a href = "#specs-video" > Specifications </a>
                    </li>
                <?php endif; ?>
                <?php if ($downloadMeta != "" || $downloadMeta != NULL) : ?>
                    <li class = "downloads_tab" >
                        <a href = "#tab-downloads" > Downloads </a>
                    </li>
                <?php endif; ?>
                <?php if ($videoMeta != "" || $videoMeta != NULL) : ?>    
                    <li class = "video_tab" >
                        <a href = "#tab-video" > Videos </a>
                    </li>
                <?php endif; ?>
    
    
                <?php foreach($tabs as $key => $tab): ?>
    
                    <li class = "<?php echo $key ?>_tab" >
                        <a href = "#tab-<?php echo $key ?>" > <? php echo apply_filters('woocommerce_product_'.$key.
                        '_tab_title', $tab['title'], $key) ?></a>
                    </li>
    
                <?php endforeach; ?>
            </ul>
            
            <?php foreach($tabs as $key => $tab): ?>
    
                <div class = "panel entry-content" id = "tab-<?php echo $key ?>" >
                    <?php call_user_func($tab['callback'], $key, $tab) ?>
                </div>
    
            <?php endforeach; ?>
            <?php endif; ?>
            <?php if ($downloadMeta != "" || $downloadMeta != NULL) : ?>
                <div class = "panel entry-content" id = "tab-downloads" >
                    <?php echo $downloadMeta; ?>
                </div>
            <?php endif; ?>
            <?php if ($videoMeta != "" || $videoMeta != NULL) : ?>
                <div class = "panel entry-content" id = "tab-video" >
                    <?php echo $videoMeta; ?>
                </div>
            <?php endif; ?>
            <?php if ($specMeta != "" || $specMeta != NULL) : ?>
                <div class = "panel entry-content" id = "specs-video" >
                    <?php echo $specMeta; ?>
                </div>
            <?php endif; ?>
        </div>
    
    <?php endif; ?>
    Let me know if it worked for you, please.
    lew1s likes this.

    My Web Site:
    brandwebdesign.ca
    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link. Some of us are really insecure and need those likes so that we feel important and smart, so come on, help us out, huh?

  11. #10
    Member lew1s's Avatar
    Join Date
    Oct 2013
    Posts
    65
    Member #
    37371
    Liked
    2 times
    its already solved. thanks Matt. just to hide tabs. content is hidden as well. thanks

    <?php if(get_post_meta(get_the_ID(), 'Specifications', TRUE)) { ?>
    <li class="specs_tab">
    <a href="#specs-video">Specifications</a>
    </li>
    <?php } ?>
    brandMatt likes this.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 05:10 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com