Let’s say you want to show the same message to all of your customers.

WooCommere has lots of hooks that we can use to show the message.

Since it’s a message that applies to all of your customers then it makes sense to put it in one central location so you can update it from there later. You can use functions.php file or a custom plugin. A custom plugin is always the recommended approach.

Why would you want to show a message?

You can notify customers about a deal, a scheduled maintenance or an upcoming sale that’s available to existing (loyal) customers only.

How to do this?

The hook we’re going to use is: woocommerce_before_account_navigation

It will show above the my account links.

You can append this (without the <?php tag) to your functions.php file or to the custom plugin you may have.
!!!Backup!!! Always backup the files you're about to edit first!

<?php

add_action('woocommerce_before_account_navigation', 'orb_post7652p_render_msg_for_all_wc_customers');

function orb_post7652p_render_msg_for_all_wc_customers()
{
    ?>
    <div class="woocommerce-info">
        Write something very important :) e.g. You can use WPSandbox.net to try or learn WordPress for free!
    </div>
    <?php
}

What was our use case?

We needed to show a message globally in our products (WPSandbox, WPDemo, StatOpt, qSandbox) but we needed it to be user specific. It's very useful to alert your customers that you have in your WooCommerce store when their credit card is about to expire so they can change it.

In the example above we used the notice class so the message is a bit neutral. If you want you can use different CSS classes to show different kind of messages.

Success message

<div class="woocommerce-message" role="alert">A success or something positive …</div>

Error Message

<div class="woocommerce-error" role="alert">An error message…</div>

Disclaimer: The content in this post is for educational purposes only. Always remember to take a backup before doing any of the suggested steps just to be on the safe side.
Referral Note: When you purchase through an referral link (if any) on this page, we may earn a commission.
If you're feeling thankful, you can buy me a coffee or a beer