WooCommerce Custom Product Tab: Don't display on certain product pages









up vote
-1
down vote

favorite












I've got a custom product tab that should appear first (over the Long Description) in my tab lineup. Problem is two of the products should not be seeing this tab at all. So I did a display: none; for that custom tab in CSS for those pages, which worked, but then you see no content in what becomes the first product tab, the long description.



So realistically, that doesn't work. It's just a band aid. So can I add some kind of an if statement to this?



add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab1' );
function woo_new_product_tab1( $tabs1 )
// Adds the new tab
$tabs1['shade_tab'] = array(
'title' => __( 'Product Tab Name', 'woocommerce' ),
'priority' => 100,
'callback' => 'woo_new_product_tab_content1'
);
return $tabs1;










share|improve this question

























    up vote
    -1
    down vote

    favorite












    I've got a custom product tab that should appear first (over the Long Description) in my tab lineup. Problem is two of the products should not be seeing this tab at all. So I did a display: none; for that custom tab in CSS for those pages, which worked, but then you see no content in what becomes the first product tab, the long description.



    So realistically, that doesn't work. It's just a band aid. So can I add some kind of an if statement to this?



    add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab1' );
    function woo_new_product_tab1( $tabs1 )
    // Adds the new tab
    $tabs1['shade_tab'] = array(
    'title' => __( 'Product Tab Name', 'woocommerce' ),
    'priority' => 100,
    'callback' => 'woo_new_product_tab_content1'
    );
    return $tabs1;










    share|improve this question























      up vote
      -1
      down vote

      favorite









      up vote
      -1
      down vote

      favorite











      I've got a custom product tab that should appear first (over the Long Description) in my tab lineup. Problem is two of the products should not be seeing this tab at all. So I did a display: none; for that custom tab in CSS for those pages, which worked, but then you see no content in what becomes the first product tab, the long description.



      So realistically, that doesn't work. It's just a band aid. So can I add some kind of an if statement to this?



      add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab1' );
      function woo_new_product_tab1( $tabs1 )
      // Adds the new tab
      $tabs1['shade_tab'] = array(
      'title' => __( 'Product Tab Name', 'woocommerce' ),
      'priority' => 100,
      'callback' => 'woo_new_product_tab_content1'
      );
      return $tabs1;










      share|improve this question













      I've got a custom product tab that should appear first (over the Long Description) in my tab lineup. Problem is two of the products should not be seeing this tab at all. So I did a display: none; for that custom tab in CSS for those pages, which worked, but then you see no content in what becomes the first product tab, the long description.



      So realistically, that doesn't work. It's just a band aid. So can I add some kind of an if statement to this?



      add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab1' );
      function woo_new_product_tab1( $tabs1 )
      // Adds the new tab
      $tabs1['shade_tab'] = array(
      'title' => __( 'Product Tab Name', 'woocommerce' ),
      'priority' => 100,
      'callback' => 'woo_new_product_tab_content1'
      );
      return $tabs1;







      woocommerce






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 10 at 5:41









      Adam Bell

      3151419




      3151419






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote













          Try the below code, change 11 and 12 to your products ID's



          add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab1' );
          function woo_new_product_tab1( $tabs1 )
          global $product;
          // Adds the new tab
          if( !$product->get_id() == 11 && !$product->get_id() == 12 )
          $tabs1['shade_tab'] = array(
          'title' => __( 'Product Tab Name', 'woocommerce' ),
          'priority' => 100,
          'callback' => 'woo_new_product_tab_content1'
          );

          return $tabs1;






          share|improve this answer






















          • That worked. The Product Tab Name tab does not appear on those two pages. Unfortunately, it now doesn't appear on any product page. I tried both && and || since it's really an one or the other, but no luck.
            – Adam Bell
            Nov 11 at 7:05










          • Make sure you have content in the tab. Also try change condition !$product->get_id() == 11 to $product->get_id() != 11 ..
            – Ahmad Hassan
            Nov 11 at 14:38










          • Definitely content in the tab. It did show up previously prior to reorganizing the tabs. I’ll try your code change / adjustment shortly. Thank you.
            – Adam Bell
            Nov 11 at 18:07










          • That change brought us back to square one.
            – Adam Bell
            Nov 11 at 19:07

















          up vote
          0
          down vote













          Here's the solution. Ahmad was close but the line should be:
          if( ! in_array( $product->get_id(), array( 232, 280 ) ) ){






          share|improve this answer




















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53236308%2fwoocommerce-custom-product-tab-dont-display-on-certain-product-pages%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote













            Try the below code, change 11 and 12 to your products ID's



            add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab1' );
            function woo_new_product_tab1( $tabs1 )
            global $product;
            // Adds the new tab
            if( !$product->get_id() == 11 && !$product->get_id() == 12 )
            $tabs1['shade_tab'] = array(
            'title' => __( 'Product Tab Name', 'woocommerce' ),
            'priority' => 100,
            'callback' => 'woo_new_product_tab_content1'
            );

            return $tabs1;






            share|improve this answer






















            • That worked. The Product Tab Name tab does not appear on those two pages. Unfortunately, it now doesn't appear on any product page. I tried both && and || since it's really an one or the other, but no luck.
              – Adam Bell
              Nov 11 at 7:05










            • Make sure you have content in the tab. Also try change condition !$product->get_id() == 11 to $product->get_id() != 11 ..
              – Ahmad Hassan
              Nov 11 at 14:38










            • Definitely content in the tab. It did show up previously prior to reorganizing the tabs. I’ll try your code change / adjustment shortly. Thank you.
              – Adam Bell
              Nov 11 at 18:07










            • That change brought us back to square one.
              – Adam Bell
              Nov 11 at 19:07














            up vote
            1
            down vote













            Try the below code, change 11 and 12 to your products ID's



            add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab1' );
            function woo_new_product_tab1( $tabs1 )
            global $product;
            // Adds the new tab
            if( !$product->get_id() == 11 && !$product->get_id() == 12 )
            $tabs1['shade_tab'] = array(
            'title' => __( 'Product Tab Name', 'woocommerce' ),
            'priority' => 100,
            'callback' => 'woo_new_product_tab_content1'
            );

            return $tabs1;






            share|improve this answer






















            • That worked. The Product Tab Name tab does not appear on those two pages. Unfortunately, it now doesn't appear on any product page. I tried both && and || since it's really an one or the other, but no luck.
              – Adam Bell
              Nov 11 at 7:05










            • Make sure you have content in the tab. Also try change condition !$product->get_id() == 11 to $product->get_id() != 11 ..
              – Ahmad Hassan
              Nov 11 at 14:38










            • Definitely content in the tab. It did show up previously prior to reorganizing the tabs. I’ll try your code change / adjustment shortly. Thank you.
              – Adam Bell
              Nov 11 at 18:07










            • That change brought us back to square one.
              – Adam Bell
              Nov 11 at 19:07












            up vote
            1
            down vote










            up vote
            1
            down vote









            Try the below code, change 11 and 12 to your products ID's



            add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab1' );
            function woo_new_product_tab1( $tabs1 )
            global $product;
            // Adds the new tab
            if( !$product->get_id() == 11 && !$product->get_id() == 12 )
            $tabs1['shade_tab'] = array(
            'title' => __( 'Product Tab Name', 'woocommerce' ),
            'priority' => 100,
            'callback' => 'woo_new_product_tab_content1'
            );

            return $tabs1;






            share|improve this answer














            Try the below code, change 11 and 12 to your products ID's



            add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab1' );
            function woo_new_product_tab1( $tabs1 )
            global $product;
            // Adds the new tab
            if( !$product->get_id() == 11 && !$product->get_id() == 12 )
            $tabs1['shade_tab'] = array(
            'title' => __( 'Product Tab Name', 'woocommerce' ),
            'priority' => 100,
            'callback' => 'woo_new_product_tab_content1'
            );

            return $tabs1;







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 11 at 0:08

























            answered Nov 10 at 23:56









            Ahmad Hassan

            212112




            212112











            • That worked. The Product Tab Name tab does not appear on those two pages. Unfortunately, it now doesn't appear on any product page. I tried both && and || since it's really an one or the other, but no luck.
              – Adam Bell
              Nov 11 at 7:05










            • Make sure you have content in the tab. Also try change condition !$product->get_id() == 11 to $product->get_id() != 11 ..
              – Ahmad Hassan
              Nov 11 at 14:38










            • Definitely content in the tab. It did show up previously prior to reorganizing the tabs. I’ll try your code change / adjustment shortly. Thank you.
              – Adam Bell
              Nov 11 at 18:07










            • That change brought us back to square one.
              – Adam Bell
              Nov 11 at 19:07
















            • That worked. The Product Tab Name tab does not appear on those two pages. Unfortunately, it now doesn't appear on any product page. I tried both && and || since it's really an one or the other, but no luck.
              – Adam Bell
              Nov 11 at 7:05










            • Make sure you have content in the tab. Also try change condition !$product->get_id() == 11 to $product->get_id() != 11 ..
              – Ahmad Hassan
              Nov 11 at 14:38










            • Definitely content in the tab. It did show up previously prior to reorganizing the tabs. I’ll try your code change / adjustment shortly. Thank you.
              – Adam Bell
              Nov 11 at 18:07










            • That change brought us back to square one.
              – Adam Bell
              Nov 11 at 19:07















            That worked. The Product Tab Name tab does not appear on those two pages. Unfortunately, it now doesn't appear on any product page. I tried both && and || since it's really an one or the other, but no luck.
            – Adam Bell
            Nov 11 at 7:05




            That worked. The Product Tab Name tab does not appear on those two pages. Unfortunately, it now doesn't appear on any product page. I tried both && and || since it's really an one or the other, but no luck.
            – Adam Bell
            Nov 11 at 7:05












            Make sure you have content in the tab. Also try change condition !$product->get_id() == 11 to $product->get_id() != 11 ..
            – Ahmad Hassan
            Nov 11 at 14:38




            Make sure you have content in the tab. Also try change condition !$product->get_id() == 11 to $product->get_id() != 11 ..
            – Ahmad Hassan
            Nov 11 at 14:38












            Definitely content in the tab. It did show up previously prior to reorganizing the tabs. I’ll try your code change / adjustment shortly. Thank you.
            – Adam Bell
            Nov 11 at 18:07




            Definitely content in the tab. It did show up previously prior to reorganizing the tabs. I’ll try your code change / adjustment shortly. Thank you.
            – Adam Bell
            Nov 11 at 18:07












            That change brought us back to square one.
            – Adam Bell
            Nov 11 at 19:07




            That change brought us back to square one.
            – Adam Bell
            Nov 11 at 19:07












            up vote
            0
            down vote













            Here's the solution. Ahmad was close but the line should be:
            if( ! in_array( $product->get_id(), array( 232, 280 ) ) ){






            share|improve this answer
























              up vote
              0
              down vote













              Here's the solution. Ahmad was close but the line should be:
              if( ! in_array( $product->get_id(), array( 232, 280 ) ) ){






              share|improve this answer






















                up vote
                0
                down vote










                up vote
                0
                down vote









                Here's the solution. Ahmad was close but the line should be:
                if( ! in_array( $product->get_id(), array( 232, 280 ) ) ){






                share|improve this answer












                Here's the solution. Ahmad was close but the line should be:
                if( ! in_array( $product->get_id(), array( 232, 280 ) ) ){







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 12 at 3:31









                Adam Bell

                3151419




                3151419



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53236308%2fwoocommerce-custom-product-tab-dont-display-on-certain-product-pages%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Darth Vader #20

                    How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

                    Ondo