• Resolved paigettie

    (@paigettie)


    Read through the forum and found a couple of posts that seemed to fit my need. applies this code (given in each of the replies) to the functions.php. Unfortunately I can still see SRP tab and info even though I’m in not logged in or in incognito mode. Am I missing something or does this code no longer work? Thanks in advance! So appreciated!

    add_filter(
    ‘yikes_woo_filter_all_product_tabs’,
    function( $tabs ) {
    if ( ! is_user_logged_in() ) {
    unset( $tabs[‘SRP’] );
    }
    return $tabs;
    }
    );

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

Viewing 15 replies - 1 through 15 (of 17 total)
  • Thread Starter paigettie

    (@paigettie)

    I’ve also tried this code and the SRP tab is still showing when incognito:

    add_filter(
    ‘yikes_woo_filter_all_product_tabs’, ‘yikes_woo_hide_tabs_from_non_logged_in_users’, 10, 2 );

    function yikes_woo_hide_tabs_from_non_logged_in_users( $tabs, $product ) {

    if ( isset( $tabs[‘SRP’] ) && ! is_user_logged_in() ) {
    unset( $tabs[‘SRP’] );
    }

    return $tabs;
    };

    • This reply was modified 4 years, 5 months ago by paigettie.
    Plugin Contributor Tracy Levesque

    (@liljimmi)

    🏳️‍🌈 YIKES, Inc. Co-Owner

    Hi @paigettie

    What are you trying to do exactly? Only show the tab to logged-in users?

    Thank you.
    -Tracy

    Thread Starter paigettie

    (@paigettie)

    Yes, only show that particular custom tab to users who are logged in. =)

    Thread Starter paigettie

    (@paigettie)

    @liljimmi
    Thanks for responding, yes, I’m trying to only show one particular custom tab only to users who are logged in.

    Thanks!

    Hi @paigettie,

    Are you sure the tab’s array key is SRP in this instance? You may want to var_dump the whole array to be sure.

    Alternatively, you might increase the filter’s priority to ensure it runs later.

    Let me know if that helps,
    Jon

    Thread Starter paigettie

    (@paigettie)

    Hi @jpowersdev, thanks for jumping in. =)

    I’m probably going to come off sounding very ignorant, I’m a newbie and know just enought code to change colors for buttons and copy code and see how to adjust it to make it work (usually, not always) for the slight variations I’m needing. So that said:

    By “tab’s array key” being SRP, this is the Tab Title, correct? (there is tab title, tab name, tab content preview) So, the tab title is SRP. If the tab array key is not the tab title, where do I look to verify the array key?

    Assuming that the array key IS the tab title, How do I var_dump? This is a new concept to me.

    As I was checking the custom tabs settings I did just realize there is the option to Toggle the_content filter, so since we are using Elementor I did toggle and save that, unfortunately it did not help. How would I increase the filter’s priority (assuming the var_dump doesn’t work)?

    Thank you so much!!

    Hi @paigettie,

    So the tabs are stored as an associative array, i.e.

    
    $tabs = array(
      'first' => array(
        'title' => 'Tab Title',
        ... etc.
      )
    );
    

    Each tab has a key in that array. In the above case, the key is first. That key should be the title, but it might be all lowercase, for example.

    var_dump is a function that lets you output a variable. In this case, you’d want to output the tabs: var_dump($tabs);. That will let you inspect the tab data array, allowing you to see the keys and use unset on the correct array member.

    To increase the priority, you change the third parameter of the add_filter function. Currently, it’s set to 10. You could change it to 20, for example, and it would execute later than other functions that use that filter with a priority of 10.

    Jon

    Thread Starter paigettie

    (@paigettie)

    @jpowersdev

    Okay, thank you, this is beginning to become a bit less murky and make sense. My next question would be, where do I perform the var_dump($tabs); to see the keys to verify or correct the code to hide the tab? Do I run that if the functions.php, or is there a plugin that I should be using that will return that info?
    Again, thank you both for your help and your patience. =)

    Hi @paigettie,

    You can do that inside the filter function you’ve already defined, presumably in your functions.php file.

    You’re welcome!

    Jon

    Thread Starter paigettie

    (@paigettie)

    @jpowersdev

    Okay, I pasted this:

    var_dump($tabs);

    in the funtions.php of the theme and clicked “update file”. It returned “file edited successfully”, but it didn’t create the tabs associative array. =( Should I be looking elsewhere for it? I feel like I’m missing something obvious… like it should be right in front of me and probably is, and somehow I’m not seeing it.

    Thread Starter paigettie

    (@paigettie)

    @jpowersdev

    I GOT IT!!!! I thought, wait, if I inspect the page, maybe I can find the tab array there, and tried it! Turns out the tab array key was #tab-srp so I put that in the code and it’s working!!! Even though I didn’t get the var_dump, I really appreciate the guidance with understanding the array sequence and the help you gave that encouraged me to see if I could find the correct key another way!

    THANK YOU!!!!!!!!!

    Thread Starter paigettie

    (@paigettie)

    @jpowersdev

    Wait, celebrated too soon. It worked when I checked it, then didn’t work after having the client check it and I’m back to seeing it again. arg! I’m so confused!!

    Thread Starter paigettie

    (@paigettie)

    @jpowersdev @liljimmi

    Since I basically ended up back at square one, I added the var_dump like this:

    add_filter(
    ‘yikes_woo_filter_all_product_tabs’, ‘yikes_woo_hide_tabs_from_non_logged_in_users’, 10, 2 );
    
    function yikes_woo_hide_tabs_from_non_logged_in_users( $tabs, $product ) {
    var_dump( $tabs );
    if ( isset( $tabs[‘srp’] ) && ! is_user_logged_in() ) {
    unset( $tabs[‘srp’] );
    }
    
    return $tabs;
    };

    First, is this correct? Second, regarding where I’m supposed to visually be able to see the output from the var_dump, I found a thread that said after updating the function.php to go to the single product page and the name of the tab would be listed there, but the page looks exactly the same to me… =( I think that is currently the biggest issue I’m having, I am not seeing anything by having a var_dump listed as above, or by itself.

    Is there any chance that using Elementor and a Child theme would be contributing to the difficulty?

    Hi @paigettie,

    Instead of yikes_woo_filter_all_product_tabs, try using the woocommerce_product_tabs filter as shown here: https://woocommerce.com/document/editing-product-data-tabs/#section-1. You’ll also need to update the callback function to only accept one parameter; $tabs.

    Let me know if that helps,
    Jon

    Thread Starter paigettie

    (@paigettie)

    @jpowersdev

    Forward progress…. I don’t know if this is what you meant, but his is what I put in the php:

    add_filter( 'woocommerce_product_tabs', 'woo_remove_product_tabs', 98 );
    
    function woo_remove_product_tabs( $tabs ) {
    
        unset( $tabs['srp'] );      	// Remove the srp tab
         
        return $tabs;
    }

    This successfully hides the tab for everyone, so now do I add this:

    if ( isset( $tabs[‘srp’] ) && ! is_user_logged_in() )

    before this:

    {
    unset( $tabs[‘srp’] ); 

    to hide the tab if not logged in?

    I hope you really feel my appreciation for your help. =)

Viewing 15 replies - 1 through 15 (of 17 total)

The topic ‘Hide Custom Tabs’ is closed to new replies.