我当前正在尝试在WordPress ajax call的函数中获得此函数的端点链接:
wc_get_endpoint_url( 'einstellungen' )
当我在WooCommerce页面中进行此操作时,我以这种格式获得了正确的链接:
www.page.com/account/einstellungen
在我的ajax函数中,url以这种方式返回:
www.page.com/einstellungen
因此,似乎缺少帐户子页面。有什么想法?
页面路径取决于您使用 wc_get_endpoint_url( $endpoint )
的位置,因此在WordPress ajax ajax ajax wp_ajax_{$action}
和/或 wp_ajax_nopriv_{$action}
中挂起的后端函数中,您将始终获得home url路径 端点slug…
相反,您有两种方法:
1(函数wc_get_account_endpoint_url( $endpoint )
可以很好地工作:
echo wc_get_account_endpoint_url( 'einstellungen' );
2(或您也可以使用wc_get_endpoint_url( $endpoint, '', $permalink )
,其中$permalink
(第三个参数(将是:
echo wc_get_endpoint_url( 'einstellungen', '', get_permalink( get_option('woocommerce_myaccount_page_id') ) );
因此,如您所见,
wc_get_endpoint_url()
功能有3个可用参数:/** * 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 = '' ) {