DEV Community

iPraxa - Web & Mobile App Development Company
iPraxa - Web & Mobile App Development Company

Posted on • Edited on

How to Add COD Handling Charges to Your Shopify Store?

Even though there are multiple ways out there to collect online payments from your customers, Cash on Delivery (COD) is still considered the most convenient and preferred mode of payment in the realm of eCommerce. According to various reports, COD accounts for nearly 60% of online sales.

Cash on Delivery Statistics

If you're using a leading eCommerce platform like Shopify and want to offer COD as a payment option to your customers, you don't have to think too much as the platform lets you enable or disable Cash on Delivery as a manual payment option. However, it doesn't natively offer any option to implement Cash On Delivery with additional charges. Means, you have to do it manually by writing custom code. For your help, here is how you can do that!

Script for Adding COD Handling Charges to Shopify

If you want to add some COD handling charges to Your Shopify Store, you first need to write or copy the following script.

window.ShopifyAnalytics.merchantGoogleAnalytics = function() {
  if(document.URL.indexOf('?previous_step=shipping_method&step=payment_method')>=0) { 
[].forEach.call(document.querySelectorAll(".order-summary__section--discount"),function(e){
            e.parentNode.removeChild(e);
        });

[].forEach.call(document.querySelectorAll(".applied-reduction-code__clear-button"),function(e){
            e.parentNode.removeChild(e);
        });

[].forEach.call(document.querySelectorAll(".field__input-btn-wrapper"),function(e){
            e.parentNode.removeChild(e);
        });     

var shippingMethod = document.getElementsByClassName('review-block__content')[2].innerText;

if(shippingMethod == 'COD · Rs. 100.00') {



[].forEach.call(document.querySelectorAll("[data-select-gateway='127248205']"),function(e){
  e.parentNode.removeChild(e);
});

document.getElementById("checkout_payment_gateway_130854093").checked = true;
document.getElementById("checkout_payment_gateway_127248205").checked = false;
}



if(shippingMethod == 'Standard shipping · Free') {
    


[].forEach.call(document.querySelectorAll("[data-select-gateway='130854093']"),function(e){
  e.parentNode.removeChild(e);
});

document.getElementById("checkout_payment_gateway_130854093").checked = false;
document.getElementById("checkout_payment_gateway_127248205").checked = true;

}
}
};

Enter fullscreen mode Exit fullscreen mode

Note: You can change the shippingMethod == parameter to anything you like.

Steps to Add the Script to Your Shopify Store

Follow the steps given below to add the above COD handling charges script to your Shopify store.

Step 1: Go to your store’s Setting page and click the Checkout tab.

Step 1

Step 2: Paste the script code in the given box.

Step 2

Step 3: Now go to your Checkout page and you’ll see that COD handling charges have started appearing there.

Step 3

That’s it!. If you're not capable to implement this script or facing any issue, feel free to contact us.

Top comments (2)

Collapse
 
alexb profile image
Alex

Hello,
I tried this too but with no luck.

Some comments may only be visible to logged-in visitors. Sign in to view all comments.