- 
      
 - 
        
Save seedcms/b955c5e007edde30944c1b647001c79b to your computer and use it in GitHub Desktop.  
    Free Gift Script
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | discounted_product = FREE GIFT PRODUCT.ID | |
| products_needed = [NEEDED PRODUCT.ID] | |
| products_seen = [] | |
| Input.cart.line_items.each do |line_item| | |
| product = line_item.variant.product | |
| products_seen << product.id if products_needed.include?(product.id) | |
| end | |
| Input.cart.line_items.each do |line_item| | |
| product = line_item.variant.product | |
| next unless product.id == discounted_product | |
| line_item.change_line_price(line_item.line_price * 0.0, message: "Free Product with Purchase") if products_seen.uniq.sort == products_needed.uniq.sort | |
| end | |
| Output.cart = Input.cart | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment