[Shopify] Create a product page where only users who have purchased a specific product can make a purchase.

There has been a request to allow only users who have purchased product A to purchase product B.
This is implemented in Shopify.

In this case, we have made it possible under the condition ‘if a product belonging to a specific collection is purchased’.

目次

Structure

The general framework is now ready for implementation.

  1. Tag users when they purchase a specific product.
    • This automates the order flow with Shopify Flow.
  2. Create a product template that will be available for purchase when a user account has a specific tag.
    • Create a new product template and replace the template for the relevant product.

1. Automate your order flow with Shopify Flow.

‘Tag a user “LoyalCustomer” when they purchase a specific product.’ We will implement the following steps.

First, install Shopify Flow.
https://apps.shopify.com/flow?locale=ja&show_store_picker=1

Once installed, the administration screen appears and you click on ‘Create Workflow’.
From this point on, it was personally difficult to understand, so if it helps… I hope it will be helpful.

Click on ‘Select trigger’.

Search for ‘Order paid’ and click on it. This is the logic that the workflow will run after the order has been placed.

Add ‘conditions’.

From Condition, click on ‘Variables’.

Select Order > lineItems. This retrieves the items in the order.

Select product.

Select ‘collections’. The collection information of the product at the time of the order is retrieved.

Select the ‘id’ of the collection.

At this point, the screen will look like the one below.
Select the target collection in the ‘Collection Id’ field and you are done.

Finally, add an ‘Action’.
Enter ‘Add customer tags’ in the search box and click ‘Add customer tags’.

Here, set the tag name you want to give to the user who made the purchase.
In this case, we use ‘LoyalCustomer’.

Turn on workflows to complete the configuration.After completion, the workflow screen will look like the one below.

This will run a trigger, so in this case, the user will be tagged when the order runs and still purchases a product that belongs to a specific collection.

2. Adding a conditional branch in the product template

We will add a conditional branch to the Shopify product template.

In practice, this needs to be separated from the main product template, but here we will only describe the conditional branching.
The user’s tags can be retrieved in customer.tags, so we’ll use that to control the conditional branching and whether or not the buy button is shown or not.
https://shopify.dev/docs/api/liquid/objects/customer#customer-tags

{% if customer.tags contains 'LoyalCustomer' %}
 {% comment %} DOM when the user's tag contains ‘LoyalCustomer’. {% endcomment %}
{% else %}
 {% comment %} DOM when not included. {% endcomment %}
{% endif %}

Click on Manage Products > Target Products, replace the ‘Theme Template’ and you are done.

Summary

What I got from this implementation is that Shopify Flow, very useful.
Orders are notified by email, but with Shopify Flow, it looks like you can do Slack notifications too. It’s very helpful that these workflows are provided free of charge to fulfil the wishes of the customers.

よかったらシェアしてね!
目次