TransWikia.com

Add checkbox to toggle custom fee to checkout

Magento Asked by coinhndp on November 5, 2021

What I am trying to do is exactly this module:
https://github.com/sivajik34/Custom-Fee-Magento2

This module adds custom fee to magento 2 and it also adds a checkbox to the checkout page. When the customer ticks the checkbox, it adds the custom fee to the cart. If not then the custom fee won’t be added.

Could someone explain how it works in the Custom-Fee-Magento2 module. I can add the custom fee to my module but don’t understand how to handle the checkbox functionality.

I am thinking of when ticking the checkbox, I use jquery to listen to that event then add a flag "isCheckboxChecked: true" to the Magento Session. And based on that boolean, I can decide whether or not to add the custom fee. But I don’t know how to use jquery to modify the magento session.

This is the js file:
https://github.com/sivajik34/Custom-Fee-Magento2/blob/master/Sivajik34/CustomFee/view/frontend/web/js/view/checkout/shipping/custom-fee.js

This is the HTML containing the checkbox:
https://github.com/sivajik34/Custom-Fee-Magento2/blob/master/Sivajik34/CustomFee/view/frontend/web/template/checkout/shipping/custom-fee.html

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP