• Resolved loopforever

    (@loopforever)


    Hi, i wish you healthy days.
    I have an e-commerce page with Woocommerce installed. I want registered customers to show their First and Last Name while commenting on the product. Also, I want the first letter of the first and last name to appear (like censorship). For example, if Matt Mullenwen comments, I want his name to appear as M *** M *** in the “reviews” section. However, in the comments, the “Display Name” defined during registration appears.
    My settings are as follows:
    ?Comment author must fill out name and email (Marked)
    ?Users must be registered and logged in to comment (Marked).
    This code sets the display name to first and last name(Because when signing up, only e-mail and password are determined at first.):

    add_action ('admin_head', 'make_display_name_f_name_last_name');
    function make_display_name_f_name_last_name () {
        $ users = get_users (array ('fields' => 'all'));
        foreach ($ users as $ user) (
            $ user = get_userdata ($ user-> ID);
            $ display_name = $ user-> first_name;
            if ($ display_name! = '') wp_update_user (array ('ID' => $ user-> ID, 'display_name' => $ display_name));
                else wp_update_user (array ('ID' => $ user-> ID, 'display_name' => $ user-> display_login));
            if ($ user-> display_name == '')
                wp_update_user (array ('ID' => $ user-> ID, 'display_name' => $ user-> display_login));
        }
    }

    This code gives the value “Anonymous” instead of the name and surname. However, I could not succeed in any way I wanted.

    add_filter ('get_comment_author', 'my_comment_author', 10, 1);
    function my_comment_author ($ author = '') {
    // Get the comment ID from WP_Query
    $ comment = get_comment ($ comment_ID);
    if (! empty ($ comment-> comment_author)) {
    if ($ comment-> user_id> 0) (
    $ user = get_userdata ($ comment-> user_id);
    $ author = $ user-> first_name. ' '.substr ($ user-> last_name, 0,1).'. '; // this is the actual line you want to change
    } else {
    $ author = __ ('Anonymous');
    }
    } else {
    $ author = $ comment-> comment_author;
    }
    return $ author;
    }
    • This topic was modified 4 years, 6 months ago by loopforever.
    • This topic was modified 4 years, 6 months ago by James Huff.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Showing the first letter of the name and surname’ is closed to new replies.