How to show custom message to specific Customer Group
Customer group specific message through HTML block.
Overview
The HTML and Javascript provided below can be pasted into an HTML block. The text within the <p>
tag will be displayed only if the customerGroupId
matches for the browsing customer.
Instructions and Examples
The example below is for the default customer group of customers who are not logged in.
Example: NOT LOGGED IN
<p id="logged-out-user-message" style="display: none;">
Message for logged out users.
</p>
<script>
var groupId = '[customerGroupId]';
if (groupId === '0') {
document.getElementById('logged-out-user-message').style.display = '';
}
</script>
This code can be changed to work for any group by replacing 0
in if (groupId === '0') {
with the Customer Group ID you want to display for.
Example: Wholesale
The Wholesale Customer Group in my test store has an ID of 14
. Yours can be found in the Customer Group list in the admin.
<p>
must match what's being selected with document.getElementById()
.The default id
doesn't have to be changed but you may if you wish.
Updated 2 days ago