Home Forums WoodMart support forum how to customize $links['my-account']['label']

how to customize $links['my-account']['label']

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #248906

    sajadsaadat
    Participant

    Hi
    I want to edit the woodmart_get_header_links function so I can change the username label.
    I used the woodmart_get_header_links filter to do this, but it doesn’t work.

    `add_filter( ‘woodmart_get_header_links’, function(){

    if( is_user_logged_in() ) {

    $current_user = wp_get_current_user();

    if( ! empty( $current_user->user_lastname ) ){
    $display_name = $current_user->user_lastname;
    }elseif( ! empty( $current_user->user_firstname ) ){
    $display_name = $current_user->user_firstname;
    }elseif( ! empty( $current_user->display_name ) ){
    $display_name = $current_user->display_name;
    }else{
    $display_name = ‘User Hi’;
    }

    $links[‘my-account’][‘label’] = sprintf( esc_html__( ‘Hello, %s’, ‘woodmart’ ), esc_html( $display_name ) );
    }

    return $links[‘my-account’][‘label’];

    },999 );

    Why?

    #249111

    Hello,

    Please try this code:

    add_filter(
    	'woodmart_get_header_links',
    	function ( $links ) {
    		if ( is_user_logged_in() ) {
    			$current_user = wp_get_current_user();
    			if ( ! empty( $current_user->user_lastname ) ) {
    				$display_name = $current_user->user_lastname;
    			} elseif ( ! empty( $current_user->user_firstname ) ) {
    				$display_name = $current_user->user_firstname;
    			} elseif ( ! empty( $current_user->display_name ) ) {
    				$display_name = $current_user->display_name;
    			} else {
    				$display_name = 'User Hi';
    			}
    			$links['my-account']['label'] = sprintf( esc_html__( 'Hello, %s', 'woodmart' ), esc_html( $display_name ) );
    		}
    		return $links;
    	},
    	999
    );

    Best Regards

Viewing 2 posts - 1 through 2 (of 2 total)