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.

4

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!!!

  • is there any alternative way i dont want to use jquery – Ronak Sep 23 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 at 13:03
  • Selected active class is not removed if I changed shipping method in this code. – Ronak Sep 23 at 13:07
  • nope. still active class is not removed if changed shipping method – Ronak Sep 23 at 13:11
  • 2
    Thanks it worked – Ronak Sep 23 at 13:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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