Created
July 6, 2024 17:42
-
-
Save shameemreza/5b89f21c03ba36378d4b3f21ddb972c5 to your computer and use it in GitHub Desktop.
Display the customer’s full name in the My Account page in WooCommerce.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add customer's full name to My Account page in WooCommerce | |
function display_customer_full_name() { | |
// Get the current user's ID | |
$user_id = get_current_user_id(); | |
// Get the user's first and last name | |
$first_name = get_user_meta($user_id, 'first_name', true); | |
$last_name = get_user_meta($user_id, 'last_name', true); | |
// Display the full name | |
if ($first_name || $last_name) { | |
echo '<p class="woocommerce-customer-name">Welcome, ' . esc_html($first_name) . ' ' . esc_html($last_name) . '!</p>'; | |
} | |
} | |
// Hook the function to WooCommerce My Account page | |
add_action('woocommerce_account_dashboard', 'display_customer_full_name'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment