Discount Function Free Shipping for Subscription Products

I followed the tutorial on building a Shopify function for discounts. The tutorial shows you how to build an automatic 10% discount based on volume. I was able to successful complete the tutorial.

However, I want to create a function that gives free shipping for the first month of signing up for a subscription product. And I cannot figure out how to alter the tutorial to do so.

I’ve gotten as far as to understand that the index.js filters by quantity (.filter(line => line.quantity >= 2 […]) for the volume example (line 29 of the file in the tutorial) and that the 10% discount is declared below that (starting at line 55, value: {percentage: {value: “10.0”}}) I have tried to detect the SellingPlanId instead of the volume, but I have been unable to get it to work.

If someone has an example of how to apply free shipping and/or how to detect if the cart item is a subscription item, it would be greatly appreciated.

According to my knowledge open the existing discount function code that you created following the tutorial. Identify the portion of the code where the discount is applied based on volume. This is the section where the percentage discount is calculated and applied to the order total. Right before or after that section, add a new conditional statement to check if the customer has signed up for a subscription product and if it’s their first month. Determine how you’re storing the subscription information for customers. If you’re using Shopify’s native subscription app, you can use Shopify’s API or Liquid code to access the subscription details.

Thanks for let me share this information to every one !!!

official website