You can unset the Address
endpoint and create a new one for Billing
. For example, in your functions.php
add the following code.
//1
function add_d_endpoint() {
add_rewrite_endpoint( 'billing', EP_ROOT | EP_PAGES );
}
add_action( 'init', 'add_d_endpoint' );
//2
function d_query_vars( $vars ) {
$vars[] = 'billing';
return $vars;
}
add_filter( 'query_vars', 'd_query_vars', 0 );
//3
function add_d_link_my_account( $items ) {
$items[ 'billing' ] = 'Billing Address'; //The title of new endpoint
return $items;
}
add_filter( 'woocommerce_account_menu_items', 'add_d_link_my_account' );
//4
function d_content() {
echo WC_Shortcode_My_Account::edit_address( 'billing' ); //The content of new endpoint
}
//5
add_action( 'woocommerce_account_billing_endpoint', 'd_content' );
// Note: add_action must follow 'woocommerce_account_{your-endpoint-slug}_endpoint' format
//6
/** Remove Address from My Account Menu **/
add_filter( 'woocommerce_account_menu_items', 'dsx_remove_my_account_dashboard' );
function dsx_remove_my_account_dashboard( $menu_links ) {
unset( $menu_links[ 'edit-address' ] ); //remove the address from endpoint
return $menu_links;
}
Then go to your Dashboard
> Settings
> Permalinks
, then click the button Save
, that should do it.
Alternatively, you can override the my-address.php
located on woocommerce/templates/myaccount
, just use WC_Shortcode_My_Account::edit_address( 'billing' );
.
Or you can redirect into Billing
when user(s) is trying to access the Edit-Address
endpoint, try using the below code in your functions.php
.
function redirect_to_billing( $wp ) {
$current_url = home_url(add_query_arg(array(),$wp->request));
$billing = home_url('/account/edit-address/billing');
/** If user is accessing edit-address endpoint and it's not the billing address**/
if(is_wc_endpoint_url('edit-address') && $current_url !== $billing){
wp_redirect($billing);
exit();
}
}
add_action( 'parse_request', 'redirect_to_billing' , 10);