• Resolved abdullahob19

    (@abdullahob19)


    Hello i was trying to change the title of tabs, what i need to make is to save tab title
    and add the product name after it so, instead of going to all products and type the title and product name i need to put the product name “the_title();” beside of it.

    Example
    the old title is : Byta Skarm/Glas
    what i want to do is:
    title : Byta Skarm/Glas + “product_title”

    can you help with that please.
    thank you in advance 🙂

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor yikesitskevin

    (@yikesitskevin)

    Hi @abdullahob19,

    Sure!

    Take a look at this snippet. This will change the title of the description tab:

    // Rename a default WooCommerce tab
    add_filter( 'woocommerce_product_tabs', 'yikes_rename_default_woocommerce_tabs', 98, 1 );
    
    function yikes_rename_default_woocommerce_tabs( $tabs ) {
    
    	if ( isset( $tabs['description'] ) ) {
    		$tabs['description']['title'] = 'My Own Text';
    	}
    
    	return $tabs;
    }

    So let’s modify that snippet with your example conditions. This will look for a tab named Byta Skarm/Glas and will append the product’s title. It will also append the title to the Description tab (just in case I got your custom tab’s title wrong).

    // Append the product's title to a tab.
    add_filter( 'woocommerce_product_tabs', 'append_product_title_to_tab_title', 98, 1 );
    
    function append_product_title_to_tab_title( $tabs ) {
    	global $post;
    
    	if ( isset( $tabs['byta-skarm-glas'] ) ) {
    		$tabs['byta-skarm-glas']['title'] = $tabs['byta-skarm-glas']['title'] . ' ' . get_the_title( $post );
    	}
    
    	if ( isset( $tabs['description'] ) ) {
    		$tabs['description']['title'] = $tabs['description']['title'] . ' ' . get_the_title( $post );
    	}
    
    	return $tabs;
    }

    Are you familiar with applying filter functions? Do you need any help adding this code to your site?

    Let me know.

    Thank you,
    Kevin.

    Thread Starter abdullahob19

    (@abdullahob19)

    Thank you so much it helped me 😀

    Plugin Contributor yikesitskevin

    (@yikesitskevin)

    You’re very welcome 🙂

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Change custom tabs titles’ is closed to new replies.