I am using WordPress with WooCommerce and WooCommerce Subscription plugins and its working fine as per my requirements.
Now I want to add my custom div
in /my-account/
page i.e. (http://www.example.com/my-account) after we login to system.
So I researched and found out this page /wp-content/plugins/woocommerce/templates/myaccount/my-account.php
and that page has below code.
<?php
defined( 'ABSPATH' ) || exit;
do_action( 'woocommerce_account_navigation' ); ?>
<div class="woocommerce-MyAccount-content">
<?php
do_action( 'woocommerce_account_content' );
?>
</div>
Hence I have added my code code something like this
<div>Test</div>
Below do_action( 'woocommerce_account_content' );
but then its appearing in all the pages like my-account/orders/
, /my-account/downloads/
etc .. I do not want it.
How can I show this only in /my-account/
page ? Additionally, how can I just overwrite this page by copying in one of my active themes so that I do not need to make changes in core files of the plugins ?
My Answer:
To add custom HTML content in the WooCommerce My Account Dashboard, you can use the `woocommerce_account_content` hook. Here's an example of how you can add a custom div after the user logs in:
1. Create a child theme if you haven't already done so.
2. In your child theme, create a new file called `myaccount.php` and copy the contents of the `my-account.php` file from the WooCommerce plugin directory.
3. Add the following code at the end of the `myaccount.php` file:
php
4. Save the file and upload it to your child theme directory.
5. Now, you can add your custom HTML content inside the `
This will add your custom div after the user logs in on the My Account page. Make sure to test it to ensure it works as expected.
Rate this post
3 of 5 based on 2967 votesComments