我有一個自定義 myaccount 頁面,我想在其中顯示儀表板.php。我們如何dashboard.php在短代碼中嵌入模板(我的帳戶“儀表板”)?我在我的中嘗試了以下操作functions.php://[account_dashboard]add_shortcode('account_dashboard', 'display_account_dashboard');function display_account_dashboard(){? ? return WC_Shortcode_My_Account::dashboard();}但這不起作用
1 回答

慕田峪7331174
TA貢獻1828條經驗 獲得超13個贊
更新:?添加了缺少的定義參數“current_user”。
要將模板myaccount/dashboard.php
嵌入到短代碼中,您可以通過以下方式使用該函數wc_get_template()
:
add_shortcode('account_dashboard', 'display_account_dashboard');
function display_account_dashboard()
{
? ? return wc_get_template(
? ? ? ? 'myaccount/dashboard.php',
? ? ? ? array(
? ? ? ? ? ? 'current_user' => get_user_by( 'id', get_current_user_id() )
? ? ? ? )
? ? );
代碼位于活動子主題(或活動主題)的functions.php 文件中。經過測試并有效。
用法: [account_dashboard]
- 1 回答
- 0 關注
- 120 瀏覽
添加回答
舉報
0/150
提交
取消