php - 如何使用简码显示 WooCommerce 我的帐户仪表板
问题描述
我有一个自定义的 myaccount 页面,我想在其中显示 dashboard.php。我们如何在简码中嵌入dashboard.php
模板(我的帐户“仪表板”)?
基于我们如何使用简码显示编辑帐户表单?回答我之前的问题,我在我的functions.php
:
//[account_dashboard]
add_shortcode('account_dashboard', 'display_account_dashboard');
function display_account_dashboard()
{
return WC_Shortcode_My_Account::dashboard();
}
但它不起作用
解决方案
更新: 添加了缺少定义的参数 "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]
推荐阅读
- javascript - 如何提取svg图像的笛卡尔坐标(x,y)?
- go - 在运行时使用字符串/变量访问常量
- python - 将 API REST 实施到现有的 Django 应用程序
- laravel - 了解 Laravel 迁移 - 是否需要创建迁移文件
- c# - 比较列表中的单个元素
到另一个列表 - firefox - Firefox 使用本机 user_pref 将可访问的 IP 地址列入白名单(不使用扩展名)
- angular - 在 Angular 的延迟加载模块中显示组件时出错
- c++ - 为什么在尝试使 i = i*i 时出现错误“使用未初始化的内存 'i'”和“使用了未初始化的局部变量 'i'”
- customization - 在 Acuamtica 升级后,通过客户休息时的事件处理程序更新位置上的自定义字段
- java - 第二次重新调用相同方法后出现 NullPointerException