-
AuthorPosts
-
July 26, 2020 at 5:50 pm #1233373
Hi,
I added this in my functions.php to modify the title of one of the tab on my products pages:add_filter( 'woocommerce_product_tabs', 'woo_rename_tabs', 98 ); function woo_rename_tabs( $tabs ) { $tabs['additional_information']['title'] = __( 'Infos' ); // Rename the additional information tab return $tabs; }
Could you please tell me what do I need to add in my function to apply it to mobile screens only?
If needed, you can find a link and credentials to my website in private content.
Thanks a lot!July 29, 2020 at 8:25 am #1233901Hey fcp,
Thank you for the inquiry.
You can wrap the changes for the additional information tab in the following function.
// https://developer.wordpress.org/reference/functions/wp_is_mobile/
Example:
if(wp_is_mobile()) { // do magic here }
Best regards,
IsmaelJuly 29, 2020 at 12:39 pm #1233935Hi Ismael,
So I tried this:if(wp_is_mobile()) { add_filter( 'woocommerce_product_tabs', 'woo_rename_tabs', 98 ); function woo_rename_tabs( $tabs ) { $tabs['additional_information']['title'] = __( 'Infos' ); // Rename the additional information tab return $tabs;} }
…but my function doesn’t work anymore :-(
What am I doing wrong?
Is it possible to indicate sizes in the function (like from XXXpx to XXXpx), instead of only “mobile”?
Thanks!August 2, 2020 at 10:51 pm #1234677Hi,
Sorry for the late reply, try this function instead:function woo_rename_tabs( $tabs ) { if(wp_is_mobile()) { $tabs['additional_information']['title'] = __( 'Infos' ); // Rename the additional information tab return $tabs; } else{ return $tabs; } } add_filter( 'woocommerce_product_tabs', 'woo_rename_tabs', 98 );
Then clear your browser cache and check.
Best regards,
MikeAugust 20, 2020 at 9:55 pm #1239633Hi Mike,
Thanks for your reply.
I’m sorry but this function doesn’t work.
Indeed, the tab tittle is not modified on any screen anymore.August 22, 2020 at 10:52 pm #1239993Hi,
When I check your tabs on a mobile device the filter is working, please see the screenshot in Private Content area.
Try clearing your browser cache and checking again.Best regards,
MikeAugust 23, 2020 at 4:01 pm #1240130Hi Mike,
Mea culpa ;-)
I only checked on my computer, resizing screen size.
But when I check on my phone, it works, you’re right!I would need one last adjustment:
I would need this function to work on mobile portrait only.
So I would prefer to set a screen size in the function.To do this, I tried to replace
if(wp_is_mobile())
byif((width >= 0) && (width <= 479))
orif((width <= 479))
but it doesn’t work, the function is now active on all screens…What am I doing wrong?
August 24, 2020 at 2:38 am #1240221Hi,
In this case the PHP function is a server-side event, getting the screen width is a client-side event, wordpress’s answer for this is the “wp_is_mobile()” function, but this relies on user agent sniffing and not actual screen size, mixing these two methods is not ideal.
Since you only want to change the text of the tab for mobile devices when in profile, I would recommend a jQuery script instead of the function.
Would you be interested in this as a solution?Best regards,
MikeAugust 24, 2020 at 11:57 pm #1240557Hi Mike,
Thanks for your reply.
If it could work and if it doesn’t need to much work for you, of course I would be interested ;-)August 27, 2020 at 2:12 pm #1241208Hi,
Sorry for the late reply, I disabled the other function and added this script, please clear your browser cache and check.function custom_woo_tab_title_script(){ ?> <script> (function($){ $(document).ready(function(){ var width = $(window).width() if ((width <= 479)) { $('.single-product #tab-title-additional_information a').each(function() { var text = $(this).text(); $(this).text(text.replace('Informations complémentaires', 'Infos')); }); } else {} }); })(jQuery); </script> <?php } add_action('wp_footer', 'custom_woo_tab_title_script');
Best regards,
MikeNovember 13, 2020 at 2:45 pm #1260347Hi Mike,
I completely forgot to thank you for your help on this thread! :-(
Your piece of code used to work perfectly, but some days ago I modified this tab translation with Loco Translate, so everything is ok on tablets and desktops, but I still would need your code to display another tab title on portrait mobiles, but it doesn’t work anymore…
What do I need to change to make it work again?
Thanks a lot ! :-)November 17, 2020 at 2:01 pm #1261001Hi,
Sorry for the late reply, I checked the product page in the Private Content area, and I believe you are referring to the tab “Caractéristiques” that changes to “Info” for mobile, please see the screenshots in Private Content area.
So I didn’t find the last code solution above in your functions.php, I did find one of the previous solutions from above in your functions.php:/*Modifier titre onglet Additional information sur mobile*/ function woo_rename_tabs( $tabs ) { if(wp_is_mobile()) { $tabs['additional_information']['title'] = __( 'Infos' ); // Rename the additional information tab return $tabs; } else{ return $tabs; } } add_filter( 'woocommerce_product_tabs', 'woo_rename_tabs', 98 );
As I recall, this code was unsatisfactory, so I commented it out and added the last solution above, modified for the new tab name:
function custom_woo_tab_title_script(){ ?> <script> (function($){ $(document).ready(function(){ var width = $(window).width() if ((width <= 479)) { $('.single-product #tab-title-additional_information a').each(function() { var text = $(this).text(); $(this).text(text.replace('Caractéristiques', 'Infos')); }); } else {} }); })(jQuery); </script> <?php } add_action('wp_footer', 'custom_woo_tab_title_script');
This seems to work correctly, this change is now live so please clear your browser cache and check.
Please note that a screen resolution change doesn’t trigger this, so when testing the page must be reloaded for the change to show, simply resizing a desktop browser to emulate a mobile browser will not work.Best regards,
MikeNovember 17, 2020 at 3:05 pm #1261015Hi Mike,
I am pretty sure I tried this updated function, switching ‘Informations complémentaires’ to ‘Caractéristiques’ inside, and it didn’t work :-(
That’s the reason why I temporarily put the older function back…
Anyway, your changes are perfect and everything works perfectly now!
Thanks a lot, Mike!November 17, 2020 at 3:26 pm #1261026Hi,
Glad to hear this helped :) we will close this now. Thank you for using Enfold.For your information, you can take a look at Enfold documentation here
For any other questions or issues, feel free to start new threads in the Enfold forum and we will gladly try to help you :)Best regards,
Mike -
AuthorPosts
- The topic ‘Modify tab title on product page on mobiles only’ is closed to new replies.