[英]Wordpress custom endpoint template doesn’t load
我正在嘗試將自定義模板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;
}
最后,我手動刷新了重寫規則,但是我的模板仍未在前端加載。 有人可以看到我在做什么錯嗎? 我在堆棧溢出方面找到了與此相關的其他帖子,但是如果我完全復制同樣的內容,對我也不起作用..有什么想法嗎?
任何幫助都非常感謝!
對活動主題的function.php
使用以下代碼。
function custom_account_details_page_endpoints() {
add_rewrite_endpoint( 'account-details', EP_ROOT | EP_PAGES );
}
add_action( 'init', 'custom_account_details_page_endpoints' );
function custom_account_details_query_vars( $vars ) {
$vars[] = 'account-details';
return $vars;
}
add_filter( 'query_vars', 'custom_account_details_query_vars', 0 );
function custom_account_details_query_vars_flush_rewrite_rules() {
flush_rewrite_rules();
}
add_action( 'wp_loaded', 'custom_account_details_query_vars_flush_rewrite_rules' );
確保將account-details.php
文件放置在myaccount
文件夾中。
function custom_account_details_endpoint_content() {
include 'woocommerce/myaccount/account-details.php';
}
add_action( 'woocommerce_account_account-details_endpoint', 'custom_account_details_endpoint_content' );
通過執行此操作,請確保通過轉到儀表板->設置->永久鏈接來更新永久鏈接,並單擊save settings
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.