matt
matt

Reputation: 249

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).

Upvotes: 1

Views: 5028

Answers (1)

ndlinh
ndlinh

Reputation: 1365

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.

Upvotes: 3

Related Questions