Halloween Sale 15% off Ends in See the plans
PHP

Custom "Support" Tab in My Account

Adds a new Support section to the My Account area with its own URL and content, for help links, a contact form shortcode or FAQs.

Don’t have WPIDE yet? Install it on your site

Code

$wpide_account_tab = array(
    'endpoint' => 'support',          // URL slug: /my-account/support/
    'label'    => 'Support',          // Menu label.
    'content'  => '<h3>Need help?</h3><p>Email us at [email protected] and we will reply within one business day.</p>',
);

add_action( 'init', function () use ( $wpide_account_tab ) {
    add_rewrite_endpoint( $wpide_account_tab['endpoint'], EP_ROOT | EP_PAGES );
} );

add_filter( 'woocommerce_get_query_vars', function ( $vars ) use ( $wpide_account_tab ) {
    $vars[ $wpide_account_tab['endpoint'] ] = $wpide_account_tab['endpoint'];

    return $vars;
} );

add_filter( 'woocommerce_account_menu_items', function ( $items ) use ( $wpide_account_tab ) {
    $logout = isset( $items['customer-logout'] ) ? $items['customer-logout'] : null;
    unset( $items['customer-logout'] );

    $items[ $wpide_account_tab['endpoint'] ] = $wpide_account_tab['label'];

    if ( $logout ) {
        $items['customer-logout'] = $logout;
    }

    return $items;
} );

add_action( 'woocommerce_account_' . $wpide_account_tab['endpoint'] . '_endpoint', function () use ( $wpide_account_tab ) {
    echo wp_kses_post( do_shortcode( $wpide_account_tab['content'] ) );
} );

add_filter( 'woocommerce_endpoint_' . $wpide_account_tab['endpoint'] . '_title', function () use ( $wpide_account_tab ) {
    return $wpide_account_tab['label'];
} );

Notes

After activating, visit Settings > Permalinks and click Save once so the new URL works. Change $content to your text or a shortcode.

How to add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.