Skip to content

aabdullaharif/shopify-functions

Repository files navigation

Shopify Extension only App

This app contains 2 functions:

  • disable-payment-for-flagged-customers
  • spend-x-get-product-y-for-z-discount

Let's discuss the details of each below:

disable-payment-for-flagged-customers

This function uses the Payment Customization API, which is responsible for hiding payment methods for customers who have the tag "flagged".

spend-x-get-product-y-for-z-discount

This function uses the Discount API to apply product-level discounts. It implements a "spend X, get product Y for Z discount" type of promotion. The function retrieves its configuration from shop metafields, including:

  • Threshold amount
  • Discounted products list
  • Discount type
  • Discount amount
  • Discount message

In short, this function makes the promotion product free when the cart value exceeds $499. (These values can be configured through metafields.)

Here are the definitions of the metafields.

shop {
  metafield(namespace: "global", key: "promo_discount_threshold") {
    value
  }
  metafield(namespace: "global", key: "promo_discount_products") {
    jsonValue
  }
  metafield(namespace: "global", key: "promo_discount_type") {
    value
  }
  metafield(namespace: "global", key: "promo_discount_amount") {
    value
  }
  metafield(namespace: "global", key: "promo_discount_message") {
    value
  }
}

Now let’s explain what each metafield does:

promo_discount_threshold

This is the threshold. When this threshold is exceeded, the function is triggered. For example, if set to 499, the promotion applies when the cart total is greater than $499.

promo_discount_products

This contains a list of product IDs that will receive the discount. You can specify one or multiple products.

promo_discount_type

Accepts two values: "Percentage" or "Dollar".

  • If "Percentage", the discount is a percentage off.
  • If "Dollar", the discount is a fixed amount off.

promo_discount_amount

Specifies the discount amount. This value depends on the promo_discount_type.

  • If type is "Percentage" and amount is 100, the product is free.
  • If type is "Dollar" and amount is 5, $5 will be discounted.

promo_discount_message

This is the label or message of the discount, which will be shown on the storefront.

About

No description, website, or topics provided.

Resources

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published