Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #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!

    #1233901

    Hey 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,
    Ismael

    #1233935

    Hi 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!

    #1234677

    Hi,
    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,
    Mike

    #1239633

    Hi 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.

    #1239993

    Hi,
    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,
    Mike

    #1240130

    Hi 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())
    by if((width >= 0) && (width <= 479))
    or if((width <= 479))
    but it doesn’t work, the function is now active on all screens…

    What am I doing wrong?

    #1240221

    Hi,
    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,
    Mike

    #1240557

    Hi 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 ;-)

    #1241208

    Hi,
    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,
    Mike

    #1260347

    Hi 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 ! :-)

    #1261001

    Hi,
    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,
    Mike

    #1261015

    Hi 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!

    #1261026

    Hi,
    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

Viewing 14 posts - 1 through 14 (of 14 total)
  • The topic ‘Modify tab title on product page on mobiles only’ is closed to new replies.