1
function bbloomer_add_premium_support_endpoint() {
    add_rewrite_endpoint( 'support', EP_ROOT | EP_PAGES );
}

add_action( 'init', 'bbloomer_add_premium_support_endpoint' );

// ------------------
// 2. Add new query var

function bbloomer_premium_support_query_vars( $vars ) {
    $vars[] = 'support';
    return $vars;
}

add_filter( 'query_vars', 'bbloomer_premium_support_query_vars', 0 );

// 3. Insert the new endpoint into the My Account menu

function bbloomer_add_premium_support_link_my_account( $items ) {
    $items['support'] = 'Premium Support';
    return $items;
}
add_filter( 'woocommerce_account_menu_items', 'bbloomer_add_premium_support_link_my_account' );
2
  • Have you flushed/re-saved your permalink settings since adding the code? Commented Jul 18, 2019 at 6:37
  • It works like charm ...thank you sir...made my day Commented Jul 18, 2019 at 6:46

1 Answer 1

1

Make sure you flush/re-save your settings in Permalinks > Settings whenever you add code the adds a rewrite endpoint or rule.

Also, the most up to date and optimal way to add an account endpoint in WooCommerce would be to use the woocommerce_get_query_vars filter:

/**
 * Register support endpoint.
 *
 * @param array $query_vars WooCommerce query vars.
 */
function wpse_343129_query_vars( $query_vars ) {
    $query_vars['support']   = 'support';

    return $query_vars;
}
add_filter( 'woocommerce_get_query_vars', 'wpse_343129_query_vars' );

It saves you having to use 2 separate functions, and ensures that you can use filters like woocommerce_endpoint_support_title to properly update the account page title:

/**
 * Support account page endpoint title.
 *
 * @param string $title Endpoint title.
 * @param string $endpoint Current endpoint.
 */
function wpse_343129_support_endpoint_title( $title, $endpoint ) {
    return 'Support';
}
add_filter( 'woocommerce_endpoint_support_title', 'wpse_343129_support_endpoint_title', 10, 2 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.