Raise the price of a product after every sale, with Mechanic.

Mechanic is an automation development platform for Shopify. :)

Raise the price of a product after every sale

by Isaac Bowen (team@usemechanic.com)

This task monitors purchases for a specific product ID, and raises the price every time it's purchased, by the amount that you specify. (To be specific, this task will raise the price on the _individual variant_ that was purchased.)

Runs when an order is paid. Configuration includes product, increase price by this much, and maximum price.

15-day free trial – unlimited tasks

Documentation

This task monitors purchases for a specific product ID, and raises the price every time it's purchased, by the amount that you specify. (To be specific, this task will raise the price on the individual variant that was purchased.)

Configure this task with the ID of the product you want to monitor. Find the product ID by opening the product in the Shopify admin, and using the numbers at the very end of the URL in your browser. For example, the product at https://example.myshopify.com/admin/products/1234567890 would have a product ID of 1234567890.

Developer details

Mechanic is designed to benefit everybody: merchants, customers, developers, agencies, Gurus, everybody.

That’s why we make it easy to configure automation without code, why we make it easy to tweak the underlying code once tasks are installed, and why we publish it all here for everyone to learn from.

Events
when an order is paid (shopify/orders/paid)
Options
product (required, number), increase price by this much (number, required), maximum price (number)
Script
{% assign purchased_variant = nil %}
{% for line_item in order.line_items %}
  {% if line_item.product_id == options.product_id__required_number %}
    {% assign purchased_variant = line_item.variant %}
    {% break %}
  {% endif %}
{% endfor %}

{% if event.preview or purchased_variant %}
  {% assign next_price = purchased_variant.price | plus: options.increase_price_by_this_much__number_required %}

  {% unless event.preview != true and options.maximum_price__number != blank and next_price > options.maximum_price__number %}
    {
      "action": {
        "type": "shopify",
        "options": [
          "update",
          [
            "variant",
            {{ purchased_variant.id | json }}
          ],
          {
            "price": {{ next_price | json }}
          }
        ]
      }
    }
  {% endunless %}
{% endif %}
Mechanic tasks are written in Liquid, which makes them easy to write and easy to modify. Learn more about our platform.