The “My Account” page in WooCommerce is a crucial part of the user experience, serving as a central hub for managing profiles, viewing order history, and more. Adding a personalized welcome message to this page can make users feel valued and engaged. In this guide, we’ll show you how to easily add a welcome message to the “My Account” page under order’s tab, creating a warm and inviting experience for your customers.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | /** * Snippet Name: Add a welcome message to my account page * Snippet Author: wpsnippets.dev */ // Add a welcome message to the "My Account" page function wps_custom_add_welcome_message() { if ( is_account_page() && is_user_logged_in() ) { $current_user = wp_get_current_user(); $user_name = $current_user ->display_name; echo '<p class="wps-welcome-message">Welcome back, ' . $user_name . '! We\'re glad to see you.</p>' ; } } add_action( 'woocommerce_before_account_orders' , 'wps_custom_add_welcome_message' ); |
Code Explanation
- This code snippet adds a welcome message to the “My Account” page’s order tab, specifically for logged-in users.
- It retrieves the current user’s display name and inserts it into the welcome message.
- The welcome message is wrapped in a paragraph tag with a custom CSS class for styling purposes.