gpt4 book ai didi

php - 如何使用短代码显示 WooCommerce 我的帐户仪表板

转载 作者:行者123 更新时间:2023-12-04 15:23:27 28 4
gpt4 key购买 nike

我有一个自定义的 myaccount 页面,我想在其中显示 dashboard.php。我们如何在短代码中嵌入 dashboard.php 模板(我的帐户“dashboard”)?

基于 How can we display the edit account form using shortcode? 回答我之前的问题,我在我的 functions.php 中尝试了以下内容:

//[account_dashboard]
add_shortcode('account_dashboard', 'display_account_dashboard');
function display_account_dashboard()
{
return WC_Shortcode_My_Account::dashboard();
}

但是没用

最佳答案

已更新: 添加了缺少定义的 argument "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]

关于php - 如何使用短代码显示 WooCommerce 我的帐户仪表板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62824890/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com