How to add a discount
When using blocks within checkout, you can leverage the Shopify Script Editor app to add discounts to products added via a checkout block. Please note that discounting behavior works differently for post purchase blocks.
Simply target any line item based on the following property:
Key: _checkoutblocks
Value: Your Block ID
Example Script
The following script can be found here: https://gist.github.com/gil--/4bf3463a2a1401acea53a8bd024d0845
BLOCK_ID = "631f8edae5f9ce785673920c" # Replace with block id DISCOUNT = 0.90 DISCOUNT_MESSAGE = "Checkout offer" Input.cart.line_items.each do |line_item| next unless line_item.properties.has_key?("_checkoutblocks") next unless line_item.properties.has_value?(BLOCK_ID) line_item.change_line_price(line_item.line_price * DISCOUNT, message: DISCOUNT_MESSAGE) end Output.cart = Input.cart
Limitations
- Currently the discounted price does not show in the block. We are working on adding a setting to enable this by end of March.
- The discount has the same limitations as any discount that uses Shopify scripts.
- You may want to add a quantity check to prevent abuse from customers changing the quantity in cart.