0

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>';

}

Mark
  • 23
  • 6
  • Do you Advanced Custom Fields(ACF) or any other plugin for creating and saving meta fields in site ? If yes, you can create a boolean meta field and use it as a toggle to show or hide new product tab, for all the products. – wpgeek1311 Aug 12 '21 at 13:45
  • Thanks will look into that – Mark Aug 12 '21 at 13:47
  • It's feasible, no extra plugin needed. What are your products and how are you going to differentiate them from each other? Based on their IDs or colors or sizes or categories? Please elaborate more! – Ruvee Aug 13 '21 at 05:13
  • Hi Ruvee The products will be differentiated by IDs or Sku, i could use category if that is easier I have added the products from one single supplier at the moment and wish to add some texct about enviromental packaging and care' however if i add a different supplier this information may be different, I basically want a quick way to add the same tabs to a group of products, but not all products – Mark Aug 16 '21 at 14:59
  • Found the answer on another post here, the code enables me to populate the tabs using CSV meaning i can copy and paste which is fine for what I want. Find it at https://stackoverflow.com/questions/52895826/custom-metabox-content-displayed-in-single-product-additional-tabs-on-woocommerc – Mark Aug 18 '21 at 13:52

0 Answers0