Unique content for My Account Dashboard landing

I’m trying to customize my WooCommerce My Account area, and it seems to be working fine except I’d like some custom content to appear only on the “Dashboard” page (that is, not on the Orders, Payment Methods, Addresses etc pages).

My problem is that I can’t figure out what Conditions to assign to make that content appear only on that page. My suspicion is that this may be because I “edited this page in Cornerstone”, and therefore Cornerstone thinks it’s a (single) Page layout, but when I tried building the page from scratch as a Layout, I couldn’t target the sub pages (Orders, etc) either.

So could you give me some guidance on:

  1. What Conditions to I need to assign to blocks I only want to appear on the Dashboard page?
  2. And I think relatedly, why does {{dc:post:title}} not work here (doesn’t change as you open sub pages)?

Thanks!

Hello Matt,

Thank you for the inquiry.

To insert additional content to the Dashboard tab, you can use the woocommerce_account_content template hook and to make sure that it’s only rendered in the dashboard, we can use the is_wc_endpoint_url function. Unfortunately, this condition is not available in the builder elements, so you may need to use the hook in this case.

We added this in the functions.php file as an example:

add_action( 'woocommerce_account_content', 'x_custom_account_dashboard_content' );

function x_custom_account_dashboard_content() {
    if ( ! is_wc_endpoint_url() ) {
        echo '<p>This is your custom content for the Dashboard page!</p>';
    }
}

Also, the dynamic content {{dc:post:title}} doesn’t update the page title because the subpages, such as Orders and Addresses, are only endpoints, not actual posts or pages.

You may wish to check out our One service where we help with 3rd party plugin and customization questions.

Best regards,
Ismael

Thanks for this, Ismael! Looks like I have some coding in front of me. One quick followup question, though:

When I change the template from “Blank, Header and Footer” to “Default”, the page is wrapped in a container with a title that DOES change depending on the sub-pages. So how is that achieved?

with a title that DOES change depending on the sub-pages.

Sorry for the confusion. It’s possible that Woocommerce filters the title based on the active endpoint. Unfortunately, this title element is not included when “Blank, Header and Footer” is active.

You can still reproduce this using a Twig template.

Example:

<h1>
    {% if url.path == 'my-account' %}
        My Account
    {% elseif url.path == 'my-account/orders' %}
        My Orders
    {% elseif url.path == 'my-account/edit-address' %}
        My Addresses
    {% elseif url.path == 'my-account/edit-account' %}
        Edit Account
    {% elseif url.path == 'my-account/downloads' %}
        Downloads
    {% elseif url.path == 'my-account/payment-methods' %}
        Payment Methods
    {% else %}
        My Account
    {% endif %}
</h1>

Then in the Headline element, you can call the Template (Include) DC:

{% include 'cs-template:id-1' %}

Make sure to replace id-1 with the actual ID of the Twig template. For more info, please check this documentation: https://theme.co/docs/twig#custom-templates

And as mentioned above, if you need assistance with custom modifications or third-party plugins, please check our One service.

Let us know if you have any further questions.

Wow cool! Thanks, Ismael!

Hey Matt,

You’re most welcome!