我有一個(gè)自定義 myaccount 頁面,我想在其中顯示儀表板.php。我們?nèi)绾蝑ashboard.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貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超13個(gè)贊
更新:?添加了缺少的定義參數(shù)“current_user”。
要將模板myaccount/dashboard.php
嵌入到短代碼中,您可以通過以下方式使用該函數(shù)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() )
? ? ? ? )
? ? );
代碼位于活動(dòng)子主題(或活動(dòng)主題)的functions.php 文件中。經(jīng)過測(cè)試并有效。
用法: [account_dashboard]
- 1 回答
- 0 關(guān)注
- 118 瀏覽
添加回答
舉報(bào)
0/150
提交
取消