4

I want to add active class When I select a shipping method on the checkout page.

For example: If I select free shipping then active class should be added on radio button which is free shipping.

Thanks in advance.

1 Answer 1

6

You can add below JS code in your checkout page for your requirement.

<script>
    require([
        'jquery'
    ], function ($) {
        $(document).ready(function () {
            $("body").on("click", "#checkout-shipping-method-load .col-method .radio", function(){
                $("#checkout-shipping-method-load .col-method .radio").removeClass("active");
                if($(this).attr("checked") == "checked") {
                    $(this).addClass("active");
                }
            });
        });
    });
</script>

Flush the cache after the changes.

Hope it helps!!!

6
  • is there any alternative way i dont want to use jquery
    – Ronak
    Sep 23, 2019 at 13:02
  • There is no other way to do this @Ronak, else you need to write this JS in your Knockout.js file
    – Sumit
    Sep 23, 2019 at 13:03
  • Selected active class is not removed if I changed shipping method in this code.
    – Ronak
    Sep 23, 2019 at 13:07
  • nope. still active class is not removed if changed shipping method
    – Ronak
    Sep 23, 2019 at 13:11
  • 2
    Thanks it worked
    – Ronak
    Sep 23, 2019 at 13:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.