Code Snippets overview

Code snippets are a feature of the Bulk Product Editor which allow you to use custom Liquid code to modify your product data. For example, the following code would set a product's status to 'Active' if it's vendor was "Ablestar":

{% if product.vendor == "Ablestar" %}

{% assign product.status = "active" %}

{% endif %}

Code snippets are a new feature that we're still fine-tuning. Please test the code carefully before applying it to your products. As with other edits, you can always undo the modifications you've made to your products. If you run into any difficulties creating a code snippet please reach out to us.

Video overview

Watch our code snippet screencast to see how you can create and use code snippets.

Why use code snippets?

Code snippets allow you to implement custom logic on your product data using Liquid code. The possibilities are almost endless but here are several use-cases that we've seen:

  • Set metafields based on values of different tags a product has
  • Automatically set Google Shopping fields for products using the values of other fields.
  • Manage a product's lifecycle, moving the product between the draft, active and archived states depending on inventory levels, images and price.
  • Set the cost of a product to vary based on which vendor it's from

How to use code snippets

You can run the code snippets against your products in three ways:

  1. As a one-off edit
  2. Every time a product is created
  3. Every time a product is updated or created

You can use a normal in-app edit to apply your code snippet to some products on a one-off basis. Just perform an in-app edit like you normally would, and select the appropriate code snippet from the 'Actions' section of the field selector.

To apply a code snippet to a product when it is created and/or updated you can use product rules. When creating a product rule, just select the code snippet as the modification you want to apply. When creating product rules with code snippets we recommend you only have a single code snippet for the product rule and include all your logic in that one snippet.

Creating code snippets

You can create and update code snippets by going to 'Automations -> Code snippets' in the left-hand menu of the app.

When you are editing a code snippet you have the ability to preview the changes a code snippet would make to a product on your store. This won't change the product but can help you confirm that the correct changes would be made. To help with debugging you have have your Liquid code put output like {{ product.vendor }} . This won't affect the field of the product but will show up in the 'Output' tab of the preview.

After you've saved a code snippet, it will show up in the field selector for in-app edits and product rules. If you modify a code snippet after you've started using it for product rules, the new version of the code snippet will be automatically applied to all upcoming products.

Liquid support in code snippets

Code snippets support all core Liquid syntax. A product variable is available to the Liquid code and modifications to that product will synced with Shopify.

The product variable is similar to the variable available when editing themes but we've added some additional field and still need to implement some Shopify-specific fields. When you're editing a code snippet and preview it against a product, the preview will show you all the data available for that product.

If you come across a missing field that you need, please let us know.

Differences between code snippets and standard Liquid

In order to support editing product data from Liquid code we've made several extensions to the Liquid language. There are also some lesser-used field on the main product object that we are still working on implementing.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.