Create a Custom Product Tab

In this tutorial you will learn not only how to create a custom tab on WooCommerce single product pages but also how to display it only for specific product types or products.

/2 comments

This is the 4th tutorial about WooCommerce product tab, in the previous ones we already talked about removing default product tabs, renaming them and changing their order.

But now we are ready to create a custom tab! It is super-easy, guys. Well, it depends on what you are going to display inside your tab, but creating tab in general is simple.

This is my tab, I use StoreFront theme, so in your theme tabs could look another way.

Create a custom product tab.

And the code:

add_filter( 'woocommerce_product_tabs', 'misha_custom_tab' );
 
function misha_custom_tab( $tabs ) {
 
	$tabs['misha_custom_tab'] = array(
		'title'    => 'About Misha',
		'callback' => 'misha_custom_tab_content', // the function name, which is on line 15
		'priority' => 50,
	);
 
	return $tabs;
 
}
 
function misha_custom_tab_content( $slug, $tab ) {
 
	echo '<h2>' . $tab['title'] . '</h2><p>Tab Content. You can display something in PHP here as well.</p>';
 
}

Read this tutorial to learn more about how to choose a priority parameter.

A quick look on the arguments of the function:

What is the reason to put $slug as a first argument of this function you may ask? Easy – it allows you to create multiple tabs and to use the same callback function for each of them. Just add a condition inside for each tab using $slug argument.

Show the Tab for Certain Product Types or Specific Products Only

You can also use global $product to create some conditions. For example you can display your tab only for certain products:

function misha_custom_tab( $tabs ) {
 
	global $product;
 
	if( $product->get_id() == 5 ) {
		$tabs['misha_custom_tab'] = array(

Or for specific product types only:

function misha_custom_tab( $tabs ) {
 
	global $product;
 
	if( $product->is_type( 'variable' ) ) {
		$tabs['misha_custom_tab'] = array(

Check other Product Tabs tutorial

Misha Rudrastyh

Misha Rudrastyh

I love WordPress, WooCommerce and Gutenberg so much. 10 yrs of experience.

Need some custom developer help? Let me know

Follow Misha

Need some help with WooCommerce?

If you need some professional developer help, I will be happy to assist you.

Contact me Who I am?

Comments — 2

Leave a comment

php js HTML CSS Code

I will only use your personal information to contact you. Privacy Policy