Adding membership to cart and instant reduction on the order

Hi,

We have created a membership that offers 10% off and free shipping. Thge membership is considered as a product and cost 19€.

BUT the user needs to pay for it first, and the reduction will be available on their next purchase. It creates two coupons, the first one is set automaticaly and the second one needs to be added manually.

I would like that when the user is making a normal purchase, if he adds the membership, it adds the discount directly.

How can i do it ?

Thank you very much,

Hi @foolitud

I totally get what you’re trying to do—you want customers to get the 10% discount immediately when they add the membership product to their cart, instead of waiting for a future purchase. That way, they feel the benefit right away, making it more appealing.

The Issue:

Right now, your membership is a standalone product, and the discount only applies to future orders through coupons. The challenge is to make it apply instantly when the membership is in the cart.

Solution:

You can achieve this using automatic discounts and Shopify Scripts (for Shopify Plus) or cart-level discount apps if you’re not on Plus. Here’s how:

1. Use Shopify Scripts (If on Shopify Plus)

If you’re on Shopify Plus, you can create a script that checks if the membership product (ID: membership_product_id) is in the cart and then applies a 10% discount to all eligible items.

Here’s an example Shopify Script (Ruby) to do this:

Apply 10% off if membership product is in cart

DISCOUNT_PERCENTAGE = 10.0

Check if membership is in cart

membership_in_cart = Input.cart.line_items.any? { |item| item.variant.product.id == membership_product_id }

if membership_in_cart

Input.cart.line_items.each do |line_item|

next if line_item.variant.product.id == membership_product_id # Skip discount on the membership itself

line_item.change_line_price(line_item.line_price * (1 - (DISCOUNT_PERCENTAGE / 100.0)), message: “Membership Discount Applied”)

end

end

Output.cart = Input.cart

2. Use Automatic Discounts (If Not on Shopify Plus)

If you’re on a standard Shopify plan, Shopify doesn’t allow dynamic discounts based on cart contents, so you’ll need a third-party app like:

  • Automatic Discounts & Gifts
  • Stackable Discounts
  • Discount Ninja

These apps allow you to set rules where, if the membership product is in the cart, a 10% discount automatically applies to the rest of the cart.

3. Use Shopify Functions (New Approach)

Shopify Functions now allow custom discount logic without Shopify Scripts. If you prefer, you can work with a developer to create a custom discount function through Shopify’s new API.

Final Thoughts:

If you’re on Shopify Plus, the Shopify Script method is the best and most seamless. Otherwise, a discount app is the easiest way to implement this without coding. Let me know which one you’re using, and I can help fine-tune it for you!

If you need extra help, just let me know asap. Thanks
Daisy.