/* Function to display the logged-in user's name */
function display_logged_in_user_name() {
    if ( is_user_logged_in() ) {
        // Get current user info
        $current_user = wp_get_current_user();
        // Display the user's display name
       // return '<p>Welcome, ' . esc_html( $current_user->display_name ) . '!</p>';
	return '<b>' . esc_html( $current_user->display_name ) . '</b>';
    } else {
        return '<p>Please log in to view your name.</p>';
    }
}
function register_user_name_shortcode() {
    add_shortcode( 'user_name', 'display_logged_in_user_name' );
}
add_action( 'init', 'register_user_name_shortcode' );
/* Function to get and display user capabilities */
function display_user_capabilities() {
    if ( is_user_logged_in() ) {
        // Get the current user
        $current_user = wp_get_current_user();
        $user_capabilities = $current_user->allcaps;
        $output = '<h3>User Capabilities</h3><ul>';
        // Loop through the capabilities and add to output
        foreach ( $user_capabilities as $capability => $granted ) {
            if ( $granted ) {
                $output .= '<li>' . esc_html( $capability ) . '</li>';
            }
        }
        $output .= '</ul>';
    } else {
        $output = '<p>Please log in to view your capabilities.</p>';
    }
    return $output;
}
// Register the shortcode
function register_user_capabilities_shortcode() {
    add_shortcode( 'user_capabilities', 'display_user_capabilities' );
}
add_action( 'init', 'register_user_capabilities_shortcode' );
/* add my account page custom menu item */
add_filter('woocommerce_account_menu_items', 'add_my_account_custom_menu_item');
function add_my_account_custom_menu_item($menu_items) {
    $menu_items['my-role-view'] = 'My membership';
    return $menu_items;
}

By admin

Leave a Reply

Your email address will not be published. Required fields are marked *