How to Automatically Tag Products When Sale Price is Lower than Compare At Price

How to Automatically Tag Products When Sale Price is Lower than Compare At Price

speakunique
New Member
6 0 0

I have a collection of products that are on sale. Right now, those products are manually tagged with a product tag "On Sale".

 

Instead of manually tagging the products, I would like to create a flow where products are tagged automatically whenever they are updated. Shopify's help bot seems to think this is possible but the steps it provides do not seem to exist.

 

Here's what it told me to do - 

Sure thing! Here's a step-by-step guide to create a workflow to tag products when the sale price is lower than the compare price:

  1. Open Shopify Flow from your Shopify admin.
  2. Click Create workflow.
  3. Set the trigger as Product updated. (This step doesn't seem to exist.)
  4. Add a condition where Product price is less than Product compare at price.
  5. Set the action to Add tag to product.

 

Does anyone know how to make this work?

Replies 24 (24)

paul_n
Shopify Staff
1814 199 430

That action doesn't exist in Flow, correct.  Product updates can be very frequent, like on every inventory change. What change do you need in order to set that tag?

 

You can use this pattern:

  • Scheduled time trigger - every hour
  • Get product data (with criteria that matches what update you care about)
  • For each (product)
    • Add product tag
       
Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.
speakunique
New Member
6 0 0

Thanks for the response. You are right about the frequency of product updates. However in this case I don't mind if it takes a few hours for the products to be labeled (and ultimately show up in the On Sale collection on the website).

 

In this case, the criteria that I care about are -

  • Price is not null
  • Compare-at-Price is not null
  • Price < Compare-at-Price
  • Product has been updated within XX hours
    • I see that Get Product Data will return a maximum of 100 products. I don't anticipate over 100 products going on sale in a single day.

 

Could you or anyone that's familiar with Flow syntax help with the remaining code needed to make this work? The problem is I don't see how to write the logic to compare the two prices. Here's what I have so far in pseudo-code (screenshot attached shows actual code)

 

  1. Run once a day at 4am
  2. Get products updated with the last day
  3. Check if the product's Compare-at-Price exists, Then
  4. Check the product's minimum Compare-at-Price is higher than or equal to the product's maximum Price (This assumes variants have prices that might be different than each other. This isn't something I'm concerned about but I'm trying to make this as helpful as possible for anyone reading it later.)
    1. I'm fairly sure what I have in the screenshot below is NOT comparing the Compare-at-Price with the Price. It seems the only option I have is to set a numeric value to compare against, which of course would defeat the whole purpose.
  5. Everything after this point is easy - do nothing if Compare-at-Price doesn't exist or is higher than price, else add product tag "On Sale".

 

P.S. The red arrow indicates were the logic problem is.

 

 

Shopify Flow.jpg

paul_n
Shopify Staff
1814 199 430

To add tags, you'll need to use a For Each step right after "Get product data". That will change your condition slightly (simplifies it a bit). Once you do that, I think you'll be able to select the correct variable (right now it's a list, so doesn't show up).

 

 

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.
speakunique
New Member
6 0 0

I'm still struggling to get this to work. I've run a number of tests and regardless of what I try, no tags are added or removed.

 

Two potential issues I see are that some of our products have variants while most do not and compare-at price is usually only filled in when a product goes on sale. For most products, compare-at price is blank.

 

I've tried to address the latter by including the first condition 'exists' but I haven't been able to find anything that talks about what 'exists' means. If a no value is entered in the compare-at price, is this field null? If a product doesn't have any variants, what am I comparing (if anything) with the current logic?

 

I'm also wondering if these conditions are comparing the exact same item in the array (or list as it's called in the flow), or is it looking for any item to meet the first condition, and then any other item to meet the second?


Here's where I'm at right now -

 

Screenshot 2024-02-20 at 9.15.20 AM.png

paul_n
Shopify Staff
1814 199 430

For your first condition, you should be using the specific item and not "Get product data". You are checking if any of the products returned has that amount. 

 

 

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.
Newbie10
Tourist
13 0 3

Hi, Do you mind sharing a screenshot of the final flow? I'm trying to set up the same thing and struggling to make it work on my end. Thank you!

paul_n
Shopify Staff
1814 199 430

I don't think a screenshot is going to help much. What part are you stuck on?

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.
Newbie10
Tourist
13 0 3

II

I'm new to creating flows... what am I doing wrong?

Screen Shot 06-05-24 at 11.01 AM.PNG

speakunique
New Member
6 0 0

Here's a screenshot, hope it helps. When setting up the conditions, make sure you're working with the returned data. Also, be aware that testing your flow can be challenging. You'll want to email yourself the products that are being returned in the array because sometimes a recently edited product would be included in the array and other times it would not.

 

Screenshot 2024-06-05 at 7.43.05 AM.png

Newbie10
Tourist
13 0 3

Thanks! This helped get me further. I replied to Paul with a screenshot of where I'm at so hopefully he can help.

paul_n
Shopify Staff
1814 199 430

For "Get product data" you can only get 100 at a time. If there are more than 100 updates per hour, you need to filter it further via the query, run it more often, or it's not going to work. It can run up to every 10 minutes. 

 

Regarding the condition, you need to try to build the condition and submit a more specific request. Your summary in the screenshot isn't detailed enough. 

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.
Newbie10
Tourist
13 0 3

Do you have any advice on building the condition? I tried exactly what Speakunique posted, what I posted, and several iterations, and can't get it to work. 

 

I will run the query more frequently, but for now just trying to get the rest to work. I do have some products currently in the last 100 updated that should have been tagged, but were not.

 

P.S. Speakunique - sorry for hijacking your threat and causing you to get alerts 😬

Newbie10
Tourist
13 0 3

I think we just got it worked out : )

speakunique
New Member
6 0 0

That's awesome @Newbie10. You should share what you changed to help out the next person. 🙂

Newbie10
Tourist
13 0 3

It's mostly working now, but still needs a few tweaks. I will for sure share once we are confident it's worked out.

Newbie10
Tourist
13 0 3

Hi Paul, can you tell me the proper way to change the "updated_at" timeframe to minutes? We tried replacing "1 hour" with "15 minutes" and ".25 hour" but neither returned the results we were expecting. 

 

updated_at:<='{{ scheduledAt }}' AND updated_at:>'{{ scheduledAt | date_minus: "1 hour" }}'

paul_n
Shopify Staff
1814 199 430

"15 minutes" should work. 

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.
AlexanderLM
Tourist
9 0 3

How do i fill out this section - i cant seem to find a way to get it to check for those things in my flow -

 

AlexanderLM_0-1718788842185.png

Screenshot 2024-06-19 at 11.22.23.png

 

speakunique
New Member
6 0 0

It's the exact same logic that was used as the conditions in the "For" loop but this time you want to use the values that were returned in the array.

 

 

Screenshot 2024-06-19 at 7.43.00 AM.png

AlexanderLM
Tourist
9 0 3

So it should look like this? - Also if i wanted to do this on specific products for example on categories or products with a specific tag - how would i go about that? Lets say i want it to check on products with the tag - T-shirts?

So that it would be > check products > check if has tag t-shirts > check if on sale (compare price thingy) and then add - on sale tag if on sale, and remove on sale tag if not on sale

Screenshot 2024-06-19 at 15.13.48.png

MilošB
Shopify Partner
1 0 0

Hello everyone,

 

It looks like some of you have a solution for this. Would any of you be so kind as to upload it here? I think many of us would appreciate it a lot.

Thanks a lot

Everlights1
Tourist
7 1 0

HI All,

I'm wanting to check back in on this thread. I've created a flow but wanting to see if anyone has any input on if it will work properly.

- this needs to check all our products (over 10,000) and add/remove the tagging accordingly.

- Should I have it look at a collection that has all the products and how would that change the flow?

Thanks for the help.

Screenshot 2025-02-05 at 11.58.39 AM.png

paul_n
Shopify Staff
1814 199 430

Not enough detail because what's in the action configuration matters (esp. the conditions and "Get product data").  

 

The rough structure looks OK for setting tags but it's unclear how its going to run on all your products ("Get" has a limit of 100 at a time and you have it scheduled to run once a day).

If you want to test your condition logic, I would start by removing the tag actions and using "Log output" instead. Then run it to verify the paths are followed as you expect. 

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.
Everlights1
Tourist
7 1 0
Thank you for this.. as I am a rookie at creating these, I would need a bit more specifics. I asked the Shopify Support team and this is what they said on my flow:

the Get product data<> action has not been properly configured. The reason is that it has no query and will currently only return a single product at random (likely most recently created). The query is something that can be built in GraphQL and I'll link all of the details below.

To get this to work you probably need to use a Get product variant<> action that includes a GraphQL product variant query<> that returns the variants you're interested in evaluating and updating (up to a limit of 100).

As building out the GraphQL query is outside of our scope of support, you could ask for help on the Flow community forums<>, which are actively monitored by our Flow team, other merchants, and agencies, who may offer a solution you can test out. Also on the actual developer document page<> there is an AI Dev assistant tool which you can use to request and generate a sample query<> - refer to my screenshot here.<>

I’m not familiar with using GraphQL or what the next steps would be.
Instead of using ‘get product data’ would it be better to use a collection that includes all our products? Is there a limit there as well?

Also, how would I use the log output?

Any specifics on how to alter the flow would be super helpful.
Thank you,