Search code examples
opencartcoupon

Restrict coupon code buy chosen currency in OpenCart


Is it possible to restrict coupon code by chosen currency in OpenCart?

E.g. Shop had two currency XX and YY. If buyer pick XX currency, Coupon code field is visible in Shopping Cart. In other case (currency YY chosen) not.

OpenCart 2.0.3.1


Solution

  • Yes, Open this file: catalog/controller/checkout/coupon.php in version 2.0.3.1

    find:

        if (empty($this->request->post['coupon'])) {
            $json['error'] = $this->language->get('error_empty');
    
            unset($this->session->data['coupon']);
        } elseif ($coupon_info) {
            $this->session->data['coupon'] = $this->request->post['coupon'];
    
            $this->session->data['success'] = $this->language->get('text_success');
    
            $json['redirect'] = $this->url->link('checkout/cart');
        } else {
            $json['error'] = $this->language->get('error_coupon');
        }
    

    change it to:

        if (empty($this->request->post['coupon'])) {
            $json['error'] = $this->language->get('error_empty');
    
            unset($this->session->data['coupon']);
        } elseif ($coupon_info) {
            // here I use USD for example
            if($this->session->data['currency'] == 'USD'){
                $this->session->data['coupon'] = $this->request->post['coupon'];
    
                $this->session->data['success'] = $this->language->get('text_success');
    
                $json['redirect'] = $this->url->link('checkout/cart');
            } else {
                // Write your custom error message here
                $json['error'] = 'This coupon is only available in USD';
    
                unset($this->session->data['coupon']);
            }
        } else {
            $json['error'] = $this->language->get('error_coupon');
        }