Blocking Affiliate and Reward Codes from Sales Items

15 Views Asked by At

For Shopify, using Script Editor, is their a code to achieve the following:

A custom script that blocks all Affiliate Codes and Reward Codes (all discount codes from 3rd party apps) from being used on any sale-items in a Shopify store?

Need a script that does the following:

  • blocks ONLY discount codes from 3rd party apps from being applied to ALL sales items.
  • allows ONLY discount codes created in Shopify to work on non-sale items.
  • allows us to select products by Tag or Collection that will be blocked from ALL 3rd party discount codes.
  • allows all (3rd Party and Shopify) discount codes to be applied to non-sale items in the cart, while NOT discounting sales items.

The following code below only works for single items AND if you have multiple items in the cart, the discount code doesn't work at all.

# ID of product you want to block
productId = 8883643220277

# Runs through a loop of items in your cart
Input.cart.line_items.each do |line_item|
  product = line_item.variant.product
  puts product.id
  next if product.gift_card?
  next unless product.id == productId
  case Input.cart.discount_code
  when CartDiscount::Percentage
    Input.cart.discount_code.reject({message: "Cannot be used with this product"})
  end
end


Output.cart = Input.cart
0

There are 0 best solutions below