简体   繁体   English

将内容添加到 WooCommerce 我的帐户仪表板主页部分

[英]Add content to WooCommerce My account dashboard main page section

Hi I have been searching for how to add items or custom HTML to the main dashboard landing page of the "my account" section of WooCommerce but cant find it.嗨,我一直在寻找如何将项目或自定义 HTML 添加到 WooCommerce 的“我的帐户”部分的主仪表板登录页面,但找不到它。 I am adding this in my child theme and all I can find through searches is how to directly edit the woocommerce_account_content .我在我的子主题中添加了这个,我可以通过搜索找到的是如何直接编辑woocommerce_account_content Since I want to do this out of my child theme should I user a filter or a hook?由于我想从我的子主题中执行此操作,我应该使用过滤器还是挂钩?

I have tried this:我试过这个:

// define the woocommerce_account_content callback 
function action_woocommerce_account_content(  ) { 
    // code here, 
}; 
         
// add the action 
add_action( 'woocommerce_account_content', 'action_woocommerce_account_content', 10, 0 ); 

But it didnt work when I simply added an echo "hello" as a test.但是当我简单地添加一个回声“你好”作为测试时它没有用。 What needs to be changed in order to add custom content to this section?为了向此部分添加自定义内容,需要更改哪些内容?

Note - There are 2 types of hooks:注意 - 有 2 种类型的钩子:

  • Filter hooks that always return a (filtered) argument总是返回(过滤的)参数的过滤器钩子
  • Action hooks that use the hook to trigger some code…使用钩子触发一些代码的动作钩子……

The action hook woocommerce_account_content is the right hook to be used and work on most themes:操作挂钩woocommerce_account_content是适用于大多数主题的正确挂钩

add_action( 'woocommerce_account_content', 'action_woocommerce_account_content' );
function action_woocommerce_account_content(  ) {
    global $current_user; // The WP_User Object

    echo '<p>' . __("This is an addition…", "woocommerce") . '</p>';
};

Code goes in functions.php file of the active child theme (or active theme).代码进入活动子主题(或活动主题)的functions.php文件。 Tested and works.测试和工作。

If it doesn't work in your case, it's due to your theme (customizations), some other plugin or some other code that you have added yourself…如果它在您的情况下不起作用,那是由于您的主题(自定义)、其他插件或您自己添加的其他代码……

First thing to do: Ask your theme's authors on their support page.要做的第一件事:在他们的支持页面上询问您主题的作者。

Related: All threads in StackOverFlow using woocommerce_account_content action hook.相关: StackOverFlow 中的所有线程都使用woocommerce_account_content操作挂钩。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM