1

Is it possible without a plugin?

Our client desperately wants the shipping method to be reset (not selected) after an order has been placed or the empty cart button is clicked.

Edit: The shipping method does indeed reset after a completed purchase. Apologies. Regardless, reset on empty cart is still an issue.

Thanks

1

You're right, this does not seem to clear automatically when you remove all line items, but you could I think just set an extra post value in your form that calls removeAllLineItems to clear the shipping handle at the same time...because in this controller there is a call to $cart->setContentFromPost('fields'); I presume if you set the shipping handle to "", that set content will cause the shipping method to be dropped from the cart.

So basically add <input type="hidden" name="shippingMethod" value=""> to your form & it should work.

| improve this answer | |
  • Hey! Thanks for the answer. Unfortunately it did not work. I tried on the default template code that comes with Commerce as well. Do you have other suggestions? Cheers! – Stian Karlsen Dec 29 '16 at 11:50
  • Yeah I realised my answer above is not right - it might be setting custom fields at that point, but not the shippingMethod. I think your best bet here is to ajax two requests off - one to updateCart to clear the shipping method/id, and then a second call to removeAllLineItems once that returns. Hacky, but it will work. – Jeremy Daalder Jan 5 '17 at 1:25
  • Could you expand on the updateCart form. I don't understand how I can use that to clear the shipping method. I tried simply creating a form and submitting it, but nothing happens. Apologies in advance for being a bother here. Thank you! (The ajax part won't be a problem, no need to expand on that) – Stian Karlsen Jan 5 '17 at 12:03

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.