WooCommerce : How to Create a Custom Product Tab on Product page.

For Adding Product Tab on Product Page we have to define tab and it’s callback in woocommerce hook 'woocommerce_product_tabs'.

The ‘woocommerce_product_tabs’ filter provided by WooCommerce should be used for adding a custom tab to a single product page in WooCommerce. The code should be added to the functions.php file of your theme.

Example :

Before


function AddNewTab( $tabs ) {
  $tabs['my_new_tab'] = array(
    'title' => 'New Tab',
    'callback' => 'new_custom_tab_content',
    'priority' => 51,
  );
}
add_filter( 'woocommerce_product_tabs', 'AddNewTab' );
function new_custom_tab_content($slug,$tab) {
  echo '<h3>' . $tab['title'] . '</h3><p>Add Your Content.</p>';
}

After

We can also do this For a Specific Product Or For Specific Product Type.

Example : For Specific Product


function AddNewTab( $tabs ) {
  global $product;
    if( $product->get_id() == 786 ) {
    $tabs['my_new_tab'] = array(
      'title' => 'New Tab',
      'callback' => 'new_custom_tab_content',
      'priority' => 51,
    );
  }
}
add_filter( 'woocommerce_product_tabs', 'AddNewTab' );
function new_custom_tab_content($slug,$tab) {
  echo '<h3>' . $tab['title'] . '</h3><p>Add Your Content.</p>';
}

Example : For Specific Product Type


function AddNewTab( $tabs ) {
  global $product;
    if( $product->is_type( 'variable' ) ) {
    $tabs['my_new_tab'] = array(
      'title' => 'New Tab',
      'callback' => 'new_custom_tab_content',
      'priority' => 51,
    );
  }
}
add_filter( 'woocommerce_product_tabs', 'AddNewTab' );
function new_custom_tab_content($slug,$tab) {
  echo '<h3>' . $tab['title'] . '</h3><p>Add Your Content.</p>';
}

Enjoy

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top