【发布时间】:2018-10-17 11:04:01
【问题描述】:
我正在尝试将自定义模板 account-details.php 添加到我的帐户区域中的新端点。
我首先添加了新的帐户详细信息端点:
add_action( 'init', 'co_add_my_account_endpoint' );
function co_add_my_account_endpoint() {
add_rewrite_endpoint( 'account-details', EP_ROOT | EP_PAGES );
}
我在这里添加自定义模板:
add_filter( 'wc_get_template', 'co_custom_endpoint', 10, 5 );
/**
* Add account details custom template
*
* @param $located
* @param $template_name
* @param $args
* @param $template_path
* @param $default_path
* @since 2.0
* @return string $located
*/
function co_custom_endpoint($located, $template_name, $args, $template_path, $default_path) {
global $wp;
if( 'myaccount/my-account.php' == $template_name ) {
$located = wc_locate_template( 'myaccount/account-details.php', $template_path, JGTB_PATH . 'templates/' );
}
return $located;
}
最后我手动刷新重写规则,但我的模板仍然没有加载到前端。任何人都可以看到我做错了什么? 我在 stack-overflow 上找到了关于此的其他帖子,但是如果我复制完全相同的内容,它也对我不起作用.. 有什么想法吗?
非常感谢任何帮助!
【问题讨论】: