Hide/open price for customers

Highlighted
New Member
2 0 0

Hello!

I use this code to hide prices for unregistered guests:

{% if customer %}
<span class="money">{{ product.price | money }}</span>
{% endif %}

But in <script  type="text/x-jquery-tmpl"> it does not work.
Prompt how correctly to insert a condition in the code.

<script id="paira-compare-template"  type="text/x-jquery-tmpl">
    <tr class="paira-product">
        <td class="f-rt">
            <a href="${url}"><img class="paira-product-image" src="${Shopify.PairaCookie.resizeImage(featured_image, "compact")}" alt="${title}"></a>
        </td>
        <td class="s-rt">
            <a href="${url}"><span class="paira-product-title">${title}</span></a>
        </td>
        <td class="t-rt text-capitalize">
            <strong><label>Vendor:</label> ${vendor}</strong>
        </td>
        <td class="fo-rt text-capitalize">
            <strong><label>Type:</label> ${type}</strong>
        </td>
        <td class="fi-rt">
            <h4 class="margin-clear">
                <label class="margin-right-10">Price:</label>
                {{if compare_at_price_min > price_min}}
                <del class="margin-right-5"><span class=money>${Shopify.formatMoney(compare_at_price_min)}</span></del>
                <span class=money>${Shopify.formatMoney(price_min)}</span>
                {{else}}


            
   <span class=money>${Shopify.formatMoney(price_min)}</span>



            
                {{/if}}
            </h4>
        </td>
        <td class="se-rt">
            <a href="#" class="paira-compare-remove compare-remove" data-handle="${handle}"><i class="fa fa-times"></i> <span>Remove</span></a>
        </td>
    </tr>
</script>

 

0 Likes
Highlighted
New Member
2 0 0

update

The solution turned out to be easier than I thought. We make two scripts one with the price of the other without.

{% if customer %}
<script> with price </script>
{% else %}
<script> without price </script>
{% endif %}

maybe come in handy

0 Likes