Allow Discount Codes by Pattern
Read the discount amount from the code itself: with the pattern PD##, the code PD15 gives 15% off. A Playwright Checkout Rules template for cart, pricing and discount codes.
What it does
Playwright looks for the pattern’s letters in the entered code and reads the number where the pattern has #. A code that matches the percentage pattern gives that percentage off; a code that matches the fixed pattern gives that many dollars off in total, split across the selected items. A code that matches neither is ignored.
These codes still need to exist in Shopify: Playwright can’t create them, because the pattern stands for many codes. Create each one as a discount in Shopify.
For example:
- '##-OFF' activates following discount codes: 01-OFF for 1% off, 02-OFF for 2% off, etc
Settings
Find it under Line Item Rules in Playwright, in Discount Codes. Give the rule a name, fill in these settings and select Save Rule.
- All or any criteria
- Whether all of the conditions you set must match for the rule to apply, or any one of them. Conditions left at “All” aren’t counted. See All or any.
- Discount if ALL of the following criteria are met
- Discount if ANY of the following criteria are met
- Eligible Customers
- Which customers the rule applies to: “All”, one customer condition, or a Multi-Select that combines up to three. See customer conditions.
- Eligible Carts in Checkout
- Which carts the rule applies to: “All”, one cart or shipping address condition, or a Multi-Select that combines up to three. See cart conditions and destination conditions.
- Eligible Line Items in Cart
- Which items in the cart get the discount: “All” items, one product condition, or a Multi-Select. See product conditions.
- Percent pattern
- Letters followed by one # per digit.
PD##readsPD10as 10% off. - Fixed pattern
- Letters followed by one # per digit.
FD###readsFD075as $75 off.
Example: Percentage codes for a sales team
- Percent pattern:
PD##. - In Shopify, create the codes
PD05,PD10andPD15.
At checkout: PD10 takes 10% off the selected items and PD15 takes 15%. Any other code is left to Shopify.
On Shopify Functions
Playwright publishes this template as part of the Shopify discount “Playwright: discount rules”, and as “Playwright: discount codes” when its rules check for codes.
- Playwright can’t create codes from a pattern: each code must exist as a discount in Shopify, and that discount gives its own value too. See Wildcards and patterns.
These conditions aren’t available in discount rules, so a rule that uses one isn’t published:
- Customer Accepts Marketing: Shopify Functions can’t see whether a customer accepts marketing. Tag those customers and use a customer tag condition instead.
- Has Properties: Line item properties aren’t available to Shopify Functions.
- Cart Total Weight: Cart weight isn’t available to Shopify Functions.
- PO Box Qualifier: Street addresses aren’t available to discount rules. Use this condition in shipping or payment rules.
- Full Address Qualifier: Street addresses aren’t available to discount rules. Use this condition in shipping or payment rules.
- Compare to billing address: Shopify Functions can’t compare billing and shipping addresses here.
- Discounted Cart Subtotal (applied by discount code): Shopify Functions only see the discount code itself, not its type or value.
Tag conditions match whole tags only. See Conditions and Publishing.