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;
woocommerce
add a comment |
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;
woocommerce
add a comment |
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;
woocommerce
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
woocommerce
asked Nov 10 at 5:41
Adam Bell
3151419
3151419
add a comment |
add a comment |
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;
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
add a comment |
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 ) ) ){
add a comment |
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;
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
add a comment |
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;
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
add a comment |
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;
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;
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
add a comment |
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
add a comment |
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 ) ) ){
add a comment |
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 ) ) ){
add a comment |
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 ) ) ){
Here's the solution. Ahmad was close but the line should be:
if( ! in_array( $product->get_id(), array( 232, 280 ) ) ){
answered Nov 12 at 3:31
Adam Bell
3151419
3151419
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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