Mit*_*ave 3 php account wordpress woocommerce woocommerce-subscriptions
我正在将 WordPress 与 WooCommerce 和 WooCommerce 订阅插件一起使用,并且其工作正常,符合我的要求。
现在我想在登录系统后div在/my-account/页面(http://www.example.com/my-account )中添加我的自定义。
所以我研究并发现了这个页面/wp-content/plugins/woocommerce/templates/myaccount/my-account.php,该页面有以下代码。
<?php
defined( 'ABSPATH' ) || exit;
do_action( 'woocommerce_account_navigation' ); ?>
<div class="woocommerce-MyAccount-content">
<?php
do_action( 'woocommerce_account_content' );
?>
</div>
Run Code Online (Sandbox Code Playgroud)
因此我添加了类似这样的代码
<div>Test</div>
Run Code Online (Sandbox Code Playgroud)
下面do_action( 'woocommerce_account_content' );,但它出现在所有页面中my-account/orders/,例如,/my-account/downloads/等等..我不想要它。
我怎样才能只在/my-account/页面中显示这个?此外,如何通过复制我的活动主题之一来覆盖此页面,以便我不需要更改插件的核心文件?
要使其仅显示在“我的帐户仪表板”中而不覆盖任何模板文件,您可以使用以下挂钩函数:
add_action( 'woocommerce_account_dashboard', 'custom_account_dashboard_content' );
function custom_account_dashboard_content(){
echo '<div>' . __("Test", "woocommerce") . '</div>';
}
Run Code Online (Sandbox Code Playgroud)
代码位于活动子主题(或活动主题)的functions.php 文件中。经过测试并有效。
自定义 html 内容仅按预期添加到“我的帐户仪表板” (不覆盖任何模板文件):
注意:这需要替换回 WooCommerce 原始相关模板文件。
| 归档时间: |
|
| 查看次数: |
4632 次 |
| 最近记录: |