How To Add Fees To Order Totals In Magento 2

- Fire development, Magento 2

Magento 2 Development; Magento 2 tutorial

If you are familiar with the way fees are added to order totals in Magento 1, you will have to master an absolutely different approach implemented in Magento 2. And below, we shed light on one of the possible ways to achieve this goal.

The desired functionality has been moved to the Quote module. You can create a new module that contains a “Fee” column. The concept of the module is described below.

The two core goals are to add a new row in “Cart Total” as well as a sidebar on the checkout page. Both elements are dedicated to fees. Besides, the fee amount is added to the total amount. Once a new order is placed, the total contains the fee. Note that the following module implements only the frontend functionality.

  1. Go to your module etc folder and create the sales.xml file there:


  1. Now, implement app\code\Sugarcode\Test\view\frontend\web\js\view\checkout\cart\totals\fee.js


  1. app\code\Sugarcode\Test\view\frontend\web\js\view\checkout\summary\fee.js


  1. app\code\Sugarcode\Test\view\frontend\web\template\checkout\summary\fee.html


  1. app\code\Sugarcode\Test\view\frontend\web\template\checkout\cart\totals\fee.html


  1. app\code\Sugarcode\Test\Model\Total\Fee.php


  1. app\code\Sugarcode\Test\etc\module.xml


  1. app\code\Sugarcode\Test\view\frontend\layout\checkout_cart_index.xml


  1. app\code\Sugarcode\Test\view\frontend\layout\checkout_index_index.xml


  1. app\code\Sugarcode\Test\view\frontend\layout\sales_order_view.xml


  1. app\code\Sugarcode\Test\Block\Sales\Order\Fee.php


Once the above steps are done, run the command below; otherwise,  your JS and HTML files won’t be available in the pub/static folder:

We hope this article was useful. It is based on the StackExchange question by Sivakumar K and answers by Pradeep Kumar. For more useful articles, check out our Cookbook.