2

I want to add active class for respected checkout step like Shipping, Review and payments step in body tag.

enter image description here

1

Override progress-bar.js in your theme

vendor/magento/module-checkout/view/frontend/web/js/view/progress-bar.js

Search below code

isProcessed: function (item) {
  return stepNavigator.isProcessed(item.code);
}

Replace

isProcessed: function (item) {
     var itemCode = item.code;
     if (itemCode == "shipping") {
             jQuery('body').addClass(item.code);
     } else {
             jQuery('body').removeClass(item.code);
     }
     return stepNavigator.isProcessed(item.code);
}

Run CLI: php bin/magento setup:static-content:deploy -f

0

Override progress-bar.js in you custom active theme(Path given below):

vendor/magento/module-checkout/view/frontend/web/js/view/progress-bar.js

Find below code:

initialize: function () {
        var stepsValue;

        this._super();
        window.addEventListener('hashchange', _.bind(stepNavigator.handleHash, stepNavigator));

        if (!window.location.hash) {
            stepsValue = stepNavigator.steps();

            if (stepsValue.length) {
                stepNavigator.setHash(stepsValue.sort(stepNavigator.sortItems)[0].code);
            }
        }

        stepNavigator.handleHash();
    },

And replace with below code:

initialize: function () {
        var stepsValue;

        this._super();
        window.addEventListener('hashchange', _.bind(stepNavigator.handleHash, stepNavigator));

        if (!window.location.hash) {
            stepsValue = stepNavigator.steps();

            if (stepsValue.length) {
                stepNavigator.setHash(stepsValue.sort(stepNavigator.sortItems)[0].code);
            }
        }

        stepNavigator.handleHash();

        // add class for default active step
        $(document.body).addClass('shipping-step');

        $(window).hashchange(_.bind(function() {
            if (window.location.hash === '#shipping') {
                $(document.body)
                    .removeClass('payment-step')
                    .addClass('shipping-step');
            }
            if (window.location.hash === '#payment') {
                $(document.body)
                    .removeClass('shipping-step')
                    .addClass('payment-step');
            }
        }));
    },

Clear cache.

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.