WooCommerce get endpoint url not returning correctly
The page path change depending on where you use wc_get_endpoint_url( $endpoint )
, so in a backend function hooked in WordPress ajax wp_ajax_{$action}
and/or wp_ajax_nopriv_{$action}
you will always get the home url path + the endpoint slug…
Instead you have 2 ways:
1) the function wc_get_account_endpoint_url( $endpoint )
that will work nicely:
echo wc_get_account_endpoint_url( 'einstellungen' );
2) Or you could also use wc_get_endpoint_url( $endpoint, '', $permalink )
, where $permalink
(the third argument) will be like:
echo wc_get_endpoint_url( 'einstellungen', '', get_permalink( get_option('woocommerce_myaccount_page_id') ) );
So now as you can see
wc_get_endpoint_url()
function has 3 available arguments:/** * Get endpoint URL. * * Gets the URL for an endpoint, which varies depending on permalink settings. * * @param string $endpoint Endpoint slug. * @param string $value Query param value. * @param string $permalink Permalink. * * @return string */function wc_get_endpoint_url( $endpoint, $value = '', $permalink = '' ) {