Step 1: Set Up Your Development Environment
Ensure you have Node.js and Shopify CLI installed.
Step 2: Install Shopify CLI
If you haven’t already installed Shopify CLI, you can do so using npm:
npm install -g @shopify/cli @shopify/theme
Step 3: Authenticate with Shopify
Log in to your Shopify Partner account using the CLI:
shopify login --store your-store-name.myshopify.com
Step 4: Create a New App
Use Shopify CLI to create a new app:
shopify app create node
Follow the prompts to:
- Enter a name for your app.
- Select your partner organization.
- Choose a development store (or create one).
Step 5: Navigate to Your App Directory
cd your-app-name
Step 6: Generate the Discount Function Extension
shopify app generate extension
Select Discount
as the type of extension.
Step 7: Develop the Function Logic
Navigate to the extensions
directory in your app, and open the discount function folder. Inside the src
directory, modify index.js
to include the logic for the 100% discount.
src/index.js
import { extend, DiscountApplicationStrategy } from '@shopify/checkout-ui-extensions';
extend('Checkout::Dynamic::Render', (root, { applyDiscount }) => {
// Apply a 100% discount to the cart
applyDiscount({
percentage: 100,
message: 'You have received a 100% discount!',
strategy: DiscountApplicationStrategy.First
});
});
Step 8: Configure the Extension
Modify shopify.extension.toml
to configure your extension:
name = "100 Percent Discount"
type = "checkout_post_purchase"
Step 9: Deploy the Function
Deploy your app and function to Shopify using the following commands:
shopify app deploy
shopify app publish
Step 10: Enable the Discount Function
- In your Shopify admin, navigate to
Settings > Checkout > Discounts
. - Enable the new discount extension and configure it as needed.
Step 11: Test Your App
Test the discount function by creating orders and checking out to ensure the 100% discount is applied.
Summary
- Set Up Environment: Install necessary tools and authenticate with Shopify.
- Create App: Use Shopify CLI to create a new Node.js app.
- Generate Extension: Create a discount function extension using Shopify CLI.
- Develop Function: Implement the logic for a 100% discount.
- Deploy and Test: Deploy your app and function, enable it in Shopify admin, and test it.
This guide provides a basic structure for creating a custom discount function in Shopify that applies a 100% discount. Customize and extend the logic as needed to fit your specific requirements.
Leave a Reply