-
-
Notifications
You must be signed in to change notification settings - Fork 312
Price Rules
Joshua Harms edited this page Dec 20, 2023
·
1 revision
The Price Rules API allows you to dynamically create discounts with multiple conditions that can be applied at checkout to cart items or shipping lines via a discount code. Price rules can be created for a fixed value discount, a percentage discount, or a shipping line discount. You can also specify the dates for which the price rule is valid, the number of times the price rule can be applied, and to which products, collections, variants, customer groups and even shipping countries the price rule can be applied.
var service = new PriceRuleService(myShopifyUrl, shopAccessToken);
var priceRule = await service.CreateAsync(new PriceRule()
{
Title = "My price rule",
ValueType = "percentage",
TargetType = "line_item",
TargetSelection = "all",
AllocationMethod = "across",
Value = -10.0m,
CustomerSelection = "all",
OncePerCustomer = false,
PrerequisiteSubtotalRange = new PrerequisiteValueRange()
{
GreaterThanOrEqualTo = 40m
},
StartsAt = new DateTimeOffset(DateTime.Now)
});
var service = new PriceRuleService(myShopifyUrl, shopAccessToken);
var updatedRule = await service.UpdateAsync(ruleId, new PriceRule()
{
Value = -15.0m
});
var service = new PriceRuleService(myShopifyUrl, shopAccessToken);
var priceRule = await service.GetAsync(ruleId);
var service = new PriceRuleService(myShopifyUrl, shopAccessToken);
var priceRules = await service.ListAsync();
var service = new PriceRuleService(myShopifyUrl, shopAccessToken);
await service.DeleteAsync(ruleId);