Create your own ecommerce website and start selling successfully with ShopWired today

Create your ecommerce website on ShopWired today.
Start today with 14 days free

Create your own ecommerce website and start selling successfully with ShopWired today

Create your ecommerce website on ShopWired today.
Start today with 14 days free

Hide prices from customers unless logged into a trade account

Theme Customisations - Coding
28th January 2021

Before you proceed:
The following article contains information that requires you to have some prior knowledge about coding in order to correctly implement the proposed change to your theme. If done incorrectly alterations made to your theme’s code can negatively impact your website causing visual and performance issues. Therefore, we strongly recommend that you only undertake this effort if you are completely confident that you know what you’re doing. If you have no coding experience at all, aren’t entirely comfortable following the instructions in this article or if you simply don’t understand the instructions then we recommend you instead contact our partners, Coding Masters, who will complete the work for you for a set fee.


Pro tip!

If you are using a version 3 or version 4 theme you won't need to add this code to your theme's files to hide your prices. Instead, you just need to activate a setting in your theme's settings.


If you're using the Trade Accounts feature, you may want to prevent visitors to your website seeing product prices unless logged into a trade account.

You can also follow the instructions below to hide things like the 'add to basket' button.

In the example above you'll see that the product's price, quantity selection and add to basket and add to wishlist buttons are hidden with a 'Please login for pricing' text link.


Wherever the code for a product price (or other elements that you want to hide) is present in your website files, you'll need to surround this with the code shown below

{% if global.customer.trade %}
        ...
{% else %}
        Please <a href="/account/login?login_redirect={{ global.current_url }}">login for pricing</a>
{% endif %}

Where ... represents the code for the elements that you want to hide unless the customer is logged in.

As shown in the example below.

Optionally you may like to include a 'click here to register' link, in which case you may want to include the code shown below.

If you do not have an account please <a href="/account/trade-application">click here to register</a>

The code for a product's price can appear in different locations in your theme's files.

home.twig - may include the code to show 'featured' products

product.twig - will include the code to show the main product page

product.twig - may include the code to show 'related' products

products.twig - will include the code to show products on a category or search results page


Testing

Once complete, you should test the feature to make sure that all of your products' prices are hidden when not logged into an account, and are displayed when logged into an account.