1

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 Answer 1

3

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>
1
  • I was able to use this solution in Magento 2, using the code here, less the next button as I just needed a way to have a link to the cart in another knockoutjs template .html file in the checkout. Thank you!
    – GuitarKat
    Apr 29, 2022 at 22:44

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.