Charge COD Fees on Shopify Without Apps

Updated On:

,By

How to Build a Shopify App That Adds a Cash on Delivery (COD) Fee Automatically?

Shopify doesn’t natively support charging extra fees based on payment method (like Cash on Delivery), which can be frustrating. In this guide, you’ll learn how to build your own Shopify app that automatically adds a COD fee as a hidden product in the cart when customers select COD payment — without any subscription fees or managing your own server (using serverless and Shopify APIs).


Overview

We’ll:

  • Create a hidden COD Fee product in your store
  • Build a Shopify app to inject a payment method selector on the cart page
  • Use Shopify AJAX API to dynamically add/remove the COD Fee product based on user selection
  • Validate COD fee on order creation using Shopify webhooks
  • Restrict COD payment method availability via Shopify’s native settings or Shopify Functions

Step 1: Create a Hidden “COD Fee” Product

  1. In Shopify Admin, create a product:
  • Name: Cash On Delivery Fee
  • Price: ₹50 (or whatever fee you want)
  • Set to available on your sales channels
  • Optionally hide from collections and search (via theme tweaks)
  1. Note down the product ID and variant ID — we’ll use these in the code.

Step 2: Build a Shopify App Boilerplate

You can use Shopify CLI to create a Node.js + React app quickly:


Step 3: Inject Payment Selector on Cart Page with ScriptTag

Shopify apps can inject JavaScript into the storefront using ScriptTag API.

Create a script file in your app (e.g., public/cod-fee.js) with:

Register the ScriptTag from your app backend:


Step 4: Validate the COD Fee on Order Creation (Webhook)

Create a webhook in your app for orders/create:

Register this webhook with Shopify when your app installs.


Step 5: Restrict COD Payment Method Based on Shipping Method

In Shopify Admin:

  • Go to Settings > Payments > Manual Payment Methods
  • Enable Cash on Delivery (COD)
  • Restrict COD availability to orders using specific shipping methods, e.g. “COD Shipping”

You can add a shipping method named “COD Shipping” and instruct customers to use that.

Alternatively, you can build a Shopify Function to enforce shipping/payment logic.


Optional: Add Shipping Method COD Fee Using Shopify Functions (Advanced)

Use Shopify CLI to create a Delivery Customization Function that adds ₹50 when shipping option contains COD. See Shopify’s docs for this advanced step.


Summary

StepWhat it does
Hidden ProductRepresents the COD fee
ScriptTag JSInjects payment method selector on cart
AJAX APIAdds/removes COD fee product dynamically
WebhookValidates COD fee on order creation
Shopify AdminRestricts COD payment method to specific shipping

Final Notes

  • This app does not alter checkout UI directly (Shopify limits this).
  • Users select payment method early on cart page, fee is added before checkout.
  • Good UX messaging is important so customers understand fees.
  • Consider edge cases like fee removal, multiple tabs, etc.

Crazy about CRO?

Dessert Calories Don’t Count

Our Sales Funnel Strategy does.

We don’t spam! Read more in our privacy policy

Leave a Reply

Your email address will not be published. Required fields are marked *