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.
Opens WPIDE on
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
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.