Hi i wish to add extra tabs to woocommerce single product. I have seen the code below which works but every product has the same tab, is there a way where i can select products where the tab would show as i want the same info on multiple products but not all products.
/**
* Add a custom product data tab
*/
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
function woo_new_product_tab( $tabs ) {
// Adds the new tab
$tabs['test_tab'] = array(
'title' => __( 'New Product Tab', 'woocommerce' ),
'priority' => 50,
'callback' => 'woo_new_product_tab_content'
);
return $tabs;
}
function woo_new_product_tab_content() {
// The new tab content
echo '<h2>New Product Tab</h2>';
echo '<p>Here\'s your new product tab.</p>';
}
Related
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;
}
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;
}
Here's the solution. Ahmad was close but the line should be:
if( ! in_array( $product->get_id(), array( 232, 280 ) ) ){
This question already has answers here:
Adding multiple tabs to WooCommerce single product pages
(3 answers)
WooCommerce single product custom Tab displaying a page content
(1 answer)
Closed 4 years ago.
Using official documentation I added custom tab in woocommerce:
/**
* Add a custom product data tab
*/
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
function woo_new_product_tab( $tabs ) {
// Adds the new tab
$tabs['test_tab'] = array(
'title' => __( 'New Product Tab', 'woocommerce' ),
'priority' => 50,
'callback' => 'woo_new_product_tab_content'
);
return $tabs;
}
function woo_new_product_tab_content() {
// The new tab content
echo '<h2>New Product Tab</h2>';
echo '<p>Here\'s your new product tab.</p>';
}
The problem is that if I try to add another tab using this code, then I get the error.
The code snippet you are trying to save produced a fatal error on line 17:
Cannot redeclare woo_new_product_tab() (previously declared in /var/www/html/sport-print.online/wp-content/plugins/code-snippets/php/snippet-ops.php(352) : eval()'d code:5)
Can you please tell me how to add another tab?
I understand my mistake =).
Work code:
/**
* Add a custom product data tab
*/
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
function woo_new_product_tab( $tabs ) {
// Adds the new tabs
$tabs['new_tab_1'] = array(
'title' => __( 'new_tab_1', 'woocommerce' ),
'priority' => 11,
'callback' => 'new_tab_1'
);
$tabs['new_tab_2'] = array(
'title' => "new_tab_2",
'priority' => 12,
'callback' => 'new_tab_2'
);
$tabs['new_tab_3'] = array(
'title' => "new_tab_3",
'priority' => 13,
'callback' => 'new_tab_3'
);
return $tabs;
}
function new_tab_1() {
// The new tab content
echo '<ol>
<li>content new_tab_1</li>
</ol>';
}
function new_tab_2() {
echo'
<h3>content new_tab_2</h3>';
}
function new_tab_3() {
echo'<p style="font-weight: bold;">content new_tab_3</p>';
}
The problem is solved.
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
function woo_new_product_tab( $tabs ) {
// Adds the new tab
$tabs['desc_tab'] = array(
'title' => __( 'Additional Information', 'woocommerce' ),
'priority' => 50,
'callback' => 'woo_new_product_tab_content'
);
}
Paste this code your active theme.
I need to add another tab to product tabs section of woocommerce with the name of features and it's content fills just like attributes section. the source be same but data store in separate meta data and show it in another tab in product page view section.
any Idea how should to do this?
thank you in advance
Here is my code
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
function woo_new_product_tab( $tabs ) {
$tabs['featurestab'] = array(
'title' => __( 'Features', 'woocommerce' ),
'priority' => 15,
'callback' => 'features_tab_content');
return $tabs;
}
function features_tab_content() {
echo 'Your product ('.get_the_ID().') features.';
}
I am using woo commerce in my wordpress store online, I got a requirement that when a product is clicked and we navigate to the product detail page. I need to show the tabs into the product page like in the link
http://www.designbyhumans.com/shop/t-shirt/men/wolf-i/17011/
In this link two additional tabs are shown
1. Phone Cases
2. Art prints
Is there any way to achieve this is woo commerce?
Please help.
You can add custom tabs using woocommerce filters
The below code adds an extra tab called 'Product Description'.
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab' );
function woo_new_product_tab( $tabs ) {
// Adds the new tab
$tabs['desc_tab'] = array(
'title' => __( 'Product Description', 'woocommerce' ),
'priority' => 50,
'callback' => 'woo_new_product_tab_content'
);
}
function woo_new_product_tab_content() {
// The new tab content
$prod_id = get_the_ID();
echo '<p>'.get_post_meta($prod_id,'product_description',true).'</p>';
}
You would need to fetch the product data into these tabs. In the above example data from a custom field(product_description) is fetched into the tab.
I have added some custom fields in woocommerce when adding product. Now i want to display those custom fields in product listing page ( wp-admin/edit.php?post_type=product ). I also want to quick edit and save like other values can be edit and save in listing page.
I tried bellow code but it did not work.
add_filter( 'manage_edit-product', 'show_product_order' );
function show_product_order($columns){
$new_columns = (is_array($columns)) ? $columns : array();
unset( $new_columns['order_actions'] );
$new_columns['product_order'] = 'Product Order';
$new_columns['order_actions'] = $columns['order_actions'];
return $new_columns;
}
I also tried below code but it did not worked too.
add_action( 'woocommerce_product_options_general_product_data', 'woocommerce_general_product_data_custom_field' );
function woocommerce_general_product_data_custom_field() {
global $woocommerce, $post;
echo '<div class="options_group">';
woocommerce_wp_checkbox(
array(
'id' => 'product_order',
'wrapper_class' => 'checkbox_class',
'label' => __('Order for Product', 'woocommerce' ),
'description' => __( 'Order for Product', 'woocommerce' )
)
);
echo '</div>';
}
i also reffered this post WooCommerce show custom column but i did not succeed to get solution
Please help.