Discount code validation via API user check

Discount code validation via API user check

Tom2024
Shopify Partner
22 0 4

I am migrating from woocommerce over to shopify and have one thing that I just can't figure out a direction to go and need some help.  I wrote some code via the functions.php in woocommerce that would take the customers email that was logged on in my store, reach out to a 3rd party website via api, check their email and if they had a tag from subscriptions (one store I check via shopify, the other is s2members which is woocomerce) or in s2members would return if they had an active paying account and allow them to use a discount code of 10%.  If they was not a paying member, then they could not use the discount code and would remove or reject the coupon code and tell them. 

 

So what do you think is the fasted and easiest way to do this.  I have the code from woocommerce if it helps to see that, but is simple stuff.

Replies 6 (6)

SBD_
Shopify Staff
1829 272 417

Hey @Tom2024 

 

Shopify Functions don't allow 3P API calls, so you won't be able to migrate the logic.

 

As a workaround, you could programatically tag customers that are subscribers, and then only allow customers with that tag to use the code (using customer segments).

 

Let me know if this suits.

Scott | Developer Advocate @ Shopify 

Tom2024
Shopify Partner
22 0 4

Is that on the roadmap to allow 3p api calls?   

so there is now way I can write something that does these checks and adds and removes tags on google sheets or something that uodates Shopify customers?   Just thinking outside the box.  

SBD_
Shopify Staff
1829 272 417

I believe it's locked down to keep checkouts performant.

 

You can absolutely write something to do these checks and add/remove tags. You just can't call APIs on the fly during checkout.

Scott | Developer Advocate @ Shopify 

Tom2024
Shopify Partner
22 0 4

So that gives me hope.  So if this was you.  What would you do?

SBD_
Shopify Staff
1829 272 417

I'd run a script to go through each customer, fire off the API checks and add/remove tags. Then, create a customer segment for customers with the specific tag. Finally, create a discount code that can only be used by that customer segment. Let me know if you have any questions or I'm missing some requirements.

Scott | Developer Advocate @ Shopify 

Tom2024
Shopify Partner
22 0 4

I meant to ask, did you happen to have an example script handy or similar I can look at to edit?