Skip to:
Content
Pages
Categories
Search
Top
Bottom

Woocommerce First and Last Names?

  • I know I’m missing something easy here but cannot find it…

    People only join my site through a Woocommerce order. Once they are joined they can request to join Private groups in BuddyPress. It looks like when someone signs up the billing_first_name and billing_last_name from Woo copy to the “Name” field in WP, but only the billing_first_name goes to the “Name” field in the BuddyPress Extended Profile.

    How can I get the BP Extended Profile name to use first and last name and match WP and Woo?

    Thanks,
    Andrew

Viewing 1 replies (of 1 total)
  • I’ve found WooCommerce is setting the display name to just the first name. It appears BP uses the display name which makes sense for BP. To change this, you can use this bit of code:

    add_filter('pre_user_display_name','g3_change_display_name');
    function g3_change_display_name($name) {
    	if ( isset( $_POST['billing_first_name'] ) ) $firstname = sanitize_text_field( $_POST['billing_first_name'] );
    	if ( isset( $_POST['billing_last_name'] ) ) $lastname = sanitize_text_field( $_POST['billing_last_name'] );
    	if ($firstname && $lastname) $name = $firstname . ' ' . $lastname;
    	return $name;
    }

    It uses a WP hook so should be good no matter what plugins you have or don’t and follows the logic from http://geektamin.com/blog/533/why-update_user_meta-display_name-doesnt-work-and-how-to-use-pre_user_display_name-instead/ if curious. Without Woo of course, the billing_first_name and billing_last_name would be different.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.
Skip to toolbar