【问题标题】:How to display WooCommerce My account dashboard using a shortcode如何使用简码显示 WooCommerce 我的帐户仪表板
【发布时间】:2020-10-30 15:22:27
【问题描述】:

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

基于 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();
}

但它不起作用

【问题讨论】:

  • 刚刚更新了我的代码……有些东西不见了。

标签: php wordpress templates woocommerce shortcode


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-24
    • 2019-10-05
    • 2016-11-21
    • 1970-01-01
    • 2022-11-24
    • 2018-05-25
    • 2015-10-25
    • 2019-06-17
    相关资源
    最近更新 更多