Add a fee based on shipping method and payment method in WooCommerce

Are you looking for an easy way to apply additional fees when a customer places an order with free shipping but wants to select Cash on Delivery payment?

WooCommerce gives you various options to design your online store in order to maximise the results of your efforts. You can add multiple codes and install a variety of plugins to make your website suit your needs.

Below is a code which allows you to set the amount of the fees and the conditions for when the fees are to be added to the checkout bill.

In order to install this option to your website, you will have to add a code to the theme functions of your active child theme.

Copy the code below and go to Dashboard > Themes > Theme editor > theme functions and paste it after the existing code.

You can change the amount of the fees by replacing it with the preset amount of 19 under the Your Setting part of the code.

After Code:

As seen in the output, the additional fee for selecting COD is added and the total has changed. And that is all there is to it to add this functionality. Let us know what you think about it in the comments section below.