Change Product Tab Titles and Headings (ok)
https://rudrastyh.com/woocommerce/rename-product-tabs-and-heading.html
Last updated
https://rudrastyh.com/woocommerce/rename-product-tabs-and-heading.html
Last updated
C:\xampp\htdocs\jp1\wp-content\themes\muum-child\functions.php
Let’s begin with the simple thing, luckily you can rename any of product tab titles, just by changing the title
element of the $tabs
array, example:
All the code from this tutorial you can insert to your functions.php
file, but please keep in mind that unless you are using your custom theme, it is better to insert the code into a child theme’s file or to a custom plugin.
By the way, if you do not need some of the default WooCommerce product tabs, you can check my another tutorial about removing them.
But it doesn’t work out the same way for the “Reviews” tab. Why? Because this tab title displays the number of customer reviews as well!
Okay, there are two different approaches for this, in the first one we can just str_replace()
the text “Reviews” and do not touch the count.
In the second approach we can get the reviews count from the global $product
object:
Ok, we’ve figured it out how to rename tabs, but it is not a complete solution without changing the tab headings as well
Each tab has a different filter hook which allows to change its heading, let’s make a look at them separately.
Everything is very similar to Description tab. Actually we have just the same code but with the different filter hook.
Here is where the interesting things come in. Yes, we have a filter hook here… it is woocommerce_reviews_title
but.. it only works in case you have reviews! So, if a product has no customer reviews, the hook won’t work!
Of course I will show you a solution, but let’s make a look on an example in case there are reviews:
As you can see, it is not necessary to get the reviews count from global $product
as we did it before, everything is already provided within filter hook arguments, you can even access a WC_Product object inside it.
And now shocking news – WooCommerce doesn’t have a hook for “Reviews” tab heading when there are no reviews!
But I promised you a solution, right?
Is it a clean solution to hook the translation? Kind of clean, if you’re absolutely sure that you have to rename this, you can use it, but please do not forget about all the conditional statements to prevent it from translating somewhere else you do not need.
And the result:
No matter what way you will choose, it should work great:
In case you do not believe me, here is a screenshot