0

I want to add an anchor link as "Return to Cart" just beside "Next" button on checkout page shipping address form. I have added an anchor tag in

app/design/frontend/Custom/theme/Magento_Checkout/web/template/shipping.html

file just above the Next button.

What I want to know is how to get checkout cart URL in href to redirect to cart page on clicking anchor tag?

Code is something like below,

<div class="actions-toolbar" id="shipping-method-buttons-container">
    <div class="primary">
        <a class="checkout-return-cart" href="#"><span translate="'Return to cart'" /></a>
        <button data-role="opc-continue" type="submit" class="button action continue primary">
              <span translate="'Next'" />
        </button>
    </div>
</div>
1

I have got the solution. It is very simple like javascript variable window.checkoutConfig contains many other variables and checkout details.

To get checkout cart URL, use window.checkoutConfig.cartUrl to get cart URL.

I have updated my code as below and it worked!

<div class="actions-toolbar" id="shipping-method-buttons-container">
     <div class="primary">
          <a class="checkout-return-cart" href="#" data-bind="attr: { href: window.checkoutConfig.cartUrl }"><span translate="'Return to cart'" /></a>
               <button data-role="opc-continue" type="submit" class="button action continue primary">
                     <span translate="'Next'" />
               </button>
     </div>
</div>

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.