Magento Function to Remove Coupon Code from a Users Cart?

Magento Function to Remove Coupon Code from a Users Cart?

I'm looking for a way to remove a coupon code from a users cart during the onestepcheckout process. Specifically, if the user enters a country that is not the USA then I'd like to remove our freeship coupon if it is set and replace it with one that offers a discount on the shipping price for the international order.

I can write all of the rest of the code, basically I'm just looking for a function that allows me to remove a set coupon code in the checkout process (if the code to add a new coupon is much different that would be helpful too).

1 Answer

I don't know how onestepcheckout work, but in onepage checkout, you can capture event "checkout_controller_onepage_save_shipping_method" and set coupon code like bellow:

function onSaveShippingMethod($observer) {
    $quote = $observer->getEvent()->getQuote();
    //remove coupon code
    $quote->setCouponCode('');
    $quote->collectTotals()->save();
}

put above method to your observer class and modify config.xml to capture event.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Sophia Al-Mansoor
Author

Sophia Al-Mansoor

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.