Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • 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' );
@mrkapable007
Copy link

Hi, thank you for this amazing code. would it be possible to show the refunded amount as store credit to the customer?
or would it be possible to allow the customer to be able to make a purchase using the refunded order amount?

Kindly assist.

@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

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