How To Add Custom Tab, Remove And Change Position Of Default Tab Woocommerce

Introduction

 
This article shows how to add a custom tab, remove and change the position of a Woocommerce single product page default tab using a Woocommerce hook,  which will be very useful.
 
In WordPress when Woocommerce is set up on your website then many things come as default like category page, shop page, product page, but in some cases users want to customize their product pages.  For this, Woocommerce provide ssome hooks and actions.
 
In this article, we will use hooks, so let me give you guys some basic ideas about the hook.
 

What is the hook?

 
The hook is one way for one piece of code to interact/modify actual code output or default code of WordPress in a simple way. You can say that it modifies actual or predefine code. Using hook you  can customize WooCommerce layout, product image, size of the product image, text of WooCommerce button and hange the position of the Woocommrece product section, and much more.
 
Example of a hook used with a filter in WordPress:
  1. function rk_custom_excerpt($output) {  
  2.     if (has_excerpt() && !is_attachment()) {  
  3.         $output. = wpb_continue_reading_link();  
  4.     }  
  5.     return $output;  
  6. }  
  7. add_filter('get_the_excerpt''rk_custom_excerpt'); 
Now you know basic things about the hook in WordPress. 

How to remove the tab on Woocommerce single product page?


If you want to remove default tabs available on the Woocommerce single product page you need to use 'woocommerce_product_tabs' hook and create your custom function like 'rk_remove_sinle_product_tabs' you can give function name as per your choice.
 
Here is a hook, you just need to copy the below code and paste into your active theme functions.php and you'll see your Woocommerce default tabs, which are available on product single page, will be removed.
  1. add_filter('woocommerce_product_tabs''rk_remove_sinle_product_tabs')  
  2.   
  3. function rk_remove_sinle_product_tabs($tabs) {  
  4.     unset($tabs['description']); // Remove the description tab    
  5.     unset($tabs['reviews']); // Remove the reviews tab    
  6.     unset($tabs['additional_information']); // Remove the additional information tab    
  7.     return $tabs;  

Now you know how to remove default on the product page in your WooCommerce template.
 
In many cases, a user wants extra tabs based on client requirements so for this Woocommerce also provides the hook.
 

How to add a custom tab on Woocommerce single product page?


If you want to add a custom tab on the Woocommerce single product page you need to use 'woocommerce_product_tabs' hook and create your custom function like 'rk_custom_product_tabs'. You can give function name as per your choice.
 
You just need to copy the below code and paste it into your active theme functions.php and you see that your Woocommerce product single page new custom tab is added.
  1. add_filter('woocommerce_product_tabs''rk_custom_product_tabs');  
  2.   
  3. function rk_custom_product_tabs($tabs) {  
  4.     $tabs = array('title' => 'Custom tab''priority' => 20'callback' => 'get_rk_custom_product_tab_content', );  
  5.     return $tabs;  
  6. }  
  7.   
  8. function get_rk_custom_product_tab_content() {  
  9.     echo "custom tab data"// code here    

Now you know how to add custom tabs on the product page in your WooCommerce template.
 
One more new case is if your client wants to change the position of your tabs, then also you can  do this type of task using Woocommerce hooks.
 

How to change the position of default/custom tab on the Woocommerce single product page?


If you want to change the position of default/custom tabs on the Woocommerce single product page you need to use 'woocommerce_product_tabs' hook and create your custom function like 'rk_change_position_tabs'. You can give function name as per your choice.
 
You just need to copy the below code and paste into your active theme functions.php and you'll see that your Woocommerce product single page new custom tab position is changed.
  1. add_filter('woocommerce_product_tabs''rk_change_position_tabs');  
  2.   
  3. function rk_reordered_tabs($tabs) {  
  4.     $tabs['cherry_wc_video']['priority'] = 5;  
  5.     $tabs['description']['priority'] = 10;  
  6.     $tabs['reviews']['priority'] = 15;  
  7.     return $tabs;  
  8. }
Now you know how to change the order of tabs on the product page in your WooCommerce template.
 

Summary


In this article, we learned how to add a custom tab, remove the default tab, and change the position of tabs in the Woocommerce single product page.
 
I hope that you found this tutorial easy to follow and understand.