Smootify.addFilter()
adds a filter after the ones added before it; returns its removal
On this page
adds a filter after the ones added before it; returns its removal New in 2.0.
addFilter<K extends keyof SmootifyFilters>(name: K, filter: SmootifyFilters[K]): () => voidTypes
SmootifyFilters
/**
* The filters of `Smootify.addFilter`, by the value they change. They run in the order they were added, each with what
* the one before answered; the async ones can await, and an error one throws stops too. Add them in a `push` function:
* it runs before Smootify asks Shopify for anything.
*/
export interface SmootifyFilters {
/**
* The lines about to be added to the cart: the add to cart forms (the main line and its add-ons at once), boxes,
* direct add, buy again, `addToCart`, `addBoxToCart` and `/cart/add.js`. The message of an error a filter throws
* shows in the form and goes out with `smootify:errors`.
*/
add_to_cart_lines: (
lines: CartLineInput[],
context: AddToCartContext,
) => FilterAnswer<CartLineInput[]> | Promise<FilterAnswer<CartLineInput[]>>;
/**
* Where the visitor goes to check out: the checkout url (or the invoice of a draft order), from the cart's checkout
* button, a buy now or `Smootify.checkout()`. Answer another url (parameters added, another checkout) or `false` to
* keep the visitor here (terms not accepted, a minimum order); the message of an error a filter throws shows in the
* cart. `smootify:initiate_checkout` goes out only when the visitor leaves.
*/
checkout_url: (
url: string,
context: CheckoutContext,
) => FilterAnswer<string> | Promise<FilterAnswer<string>>;
/**
* The draft order about to be created (Draft Orders, server plan): a quote, or a checkout or buy now with a custom
* price. An error a filter throws shows in the cart or the form.
*/
draft_order_data: (
data: DraftOrderData,
context: DraftOrderContext,
) => FilterAnswer<DraftOrderData> | Promise<FilterAnswer<DraftOrderData>>;
/**
* The metafields the products and the cart ask Shopify for, for each kind of `[metafield]` element on the page (add
* the ones a script reads, remove the ones nobody shows). Synchronous: it cannot stop, and an error it throws is
* logged and the filter skipped.
*/
metafield_definitions: (
definitions: MetafieldIdentifier[],
context: MetafieldDefinitionsContext,
) => MetafieldIdentifier[] | undefined;
}