Link Displayed According To Tag On The /Account Page

Solved

Link Displayed According To Tag On The /Account Page

Guifonte
Tourist
25 0 2

Hi everyone,

 

I'm looking for a custom code (no apps please) that allow me to display a link into the account page, according to a specific customer tag.

 

I basically want to show a link that is going to redirect a tagged customer to another specific page. However, there will be more than one tag. Eg: Customer tagged "A" should see just the link for "A". If there is no tag, it doesn't show anything.

 

TIA.

 

Gui

Accepted Solution (1)

Danishshopdev
Shopify Partner
163 17 20

This is an accepted solution.

hey @Guifonte 

 

paste this code in your account page, at end of the file, 

 

 

{% if customer %}
    <script>
        var customerTags = {{ customer.tags | json }};
    </script>
{% endif %}


<script>
    document.addEventListener('DOMContentLoaded', function() {
        var links = {
            'TagA': 'https://example.com/link-for-tag-a',
            'TagB': 'https://example.com/link-for-tag-b',
            // Add more tag-to-link mappings as needed
        };

        var linkToDisplay = '';
        customerTags.forEach(function(tag) {
            if (links[tag]) {
                linkToDisplay = links[tag];
            }
        });

        if (linkToDisplay) {
            renderLink(linkToDisplay);
        }
    });

    function renderLink(link) {
        var linkElement = document.createElement('a');
        linkElement.href = link;
        linkElement.textContent = 'Special Link for You'; // Customize this text as needed
        document.getElementById('account-page-container').appendChild(linkElement);
    }
</script>

 

 

and to render the link paste this one  to display it on screen.

<div id="account-page-container">
    <!-- Customer account details -->
</div>

 

banned

View solution in original post

Replies 4 (4)

Danishshopdev
Shopify Partner
163 17 20

This is an accepted solution.

hey @Guifonte 

 

paste this code in your account page, at end of the file, 

 

 

{% if customer %}
    <script>
        var customerTags = {{ customer.tags | json }};
    </script>
{% endif %}


<script>
    document.addEventListener('DOMContentLoaded', function() {
        var links = {
            'TagA': 'https://example.com/link-for-tag-a',
            'TagB': 'https://example.com/link-for-tag-b',
            // Add more tag-to-link mappings as needed
        };

        var linkToDisplay = '';
        customerTags.forEach(function(tag) {
            if (links[tag]) {
                linkToDisplay = links[tag];
            }
        });

        if (linkToDisplay) {
            renderLink(linkToDisplay);
        }
    });

    function renderLink(link) {
        var linkElement = document.createElement('a');
        linkElement.href = link;
        linkElement.textContent = 'Special Link for You'; // Customize this text as needed
        document.getElementById('account-page-container').appendChild(linkElement);
    }
</script>

 

 

and to render the link paste this one  to display it on screen.

<div id="account-page-container">
    <!-- Customer account details -->
</div>

 

banned
Guifonte
Tourist
25 0 2

Hi there,

 

Thank you for your reply.

 

Can you please tell me where to find the account page?

I have attached a screenshot of my theme code settings.

Screenshot 2024-01-25 at 10.54.48 am.png

 

Guifonte
Tourist
25 0 2

I have just added a custom liquid code directly in the page through the theme customiser. 

 

I come back if to say if that works, thanks a lot

Danishshopdev
Shopify Partner
163 17 20

Sure. let me know if its works or not.

banned