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. I am adding this in my child theme and all I can find through searches is how to directly edit the 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?
Advertisement
Answer
Note – There are 2 types of hooks:
- 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:
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). 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.