Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alhoseany/44f354d3375c924c3e185ab5be31aabd to your computer and use it in GitHub Desktop.
Save alhoseany/44f354d3375c924c3e185ab5be31aabd to your computer and use it in GitHub Desktop.
Add custom menu item and endpoint to WooCommerce my-account page
/* Add custom menu item and endpoint to WooCommerce My-Account page */
function my_custom_endpoints() {
add_rewrite_endpoint( 'refunds-returns', EP_ROOT | EP_PAGES );
}
add_action( 'init', 'my_custom_endpoints' );
// so you can use is_wc_endpoint_url( 'refunds-returns' )
add_filter( 'woocommerce_get_query_vars', 'my_custom_woocommerce_query_vars', 0 );
function my_custom_woocommerce_query_vars( $vars ) {
$vars['refunds-returns'] = 'refunds-returns';
return $vars;
}
function my_custom_flush_rewrite_rules() {
flush_rewrite_rules();
}
add_action( 'after_switch_theme', 'my_custom_flush_rewrite_rules' );
function my_custom_my_account_menu_items( $items ) {
$new_item = array( 'refunds-returns' => __( 'Refunds & Returns', 'woocommerce' ) );
// add item in 2nd place
$items = array_slice($items, 0, 1, TRUE) + $new_item + array_slice($items, 1, NULL, TRUE);
return $items;
}
add_filter( 'woocommerce_account_menu_items', 'my_custom_my_account_menu_items' );
function my_custom_endpoint_content() {
wc_get_template( 'myaccount/refunds-returns.php');
}
add_action( 'woocommerce_account_refunds-returns_endpoint', 'my_custom_endpoint_content' );
@alhoseany
Copy link
Author

Hi,
Yes, this is possible. But this will require totally different code. If you would like a paid help you can hire me here:
https://app.codeable.io/tasks/new?preferredContractor=24124

@haxmart
Copy link

haxmart commented Jun 3, 2024

This was really helpful, thank you!

A note for anyone here in future: make sure you flush your permalinks after adding the code, or else your new endpoint will 404.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment