Search code examples
opencartopencart-3

How to get Country ISO code in OpenCart invoice?


I want zone code in stead of Zone name and Country code in stead of Country name in the invoice only.

Like: First Name, Address line 1, West Sussex, United Kingdom

As: First Name, Address line 1, SXW, UK

I've made some modification in the following file:

public_html/_admin/controller/sale/order.php

            if ($order_info['shipping_address_format']) {
                $format = $order_info['shipping_address_format'];
            } else {
                $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . ", " . '{address_2}' . ", " . '{city} {postcode}' . ", " . '{zone_code}' . "\n" . '{country_code}'; 
            }

I'm getting the zone code fine, but not getting Country code, it's showing '{country_code}' only.

How to fix this? Thanks in advance.


Solution

  • Update file as below: `$find = array( '{firstname}', '{lastname}', '{company}', '{address_1}', '{address_2}', '{city}', '{postcode}', '{zone}', '{zone_code}', '{country}', '{country_code}' );

            $replace = array(
                'firstname' => $order_info['payment_firstname'],
                'lastname'  => $order_info['payment_lastname'],
                'company'   => $order_info['payment_company'],
                'address_1' => $order_info['payment_address_1'],
                'address_2' => $order_info['payment_address_2'],
                'city'      => $order_info['payment_city'],
                'postcode'  => $order_info['payment_postcode'],
                'zone'      => $order_info['payment_zone'],
                'zone_code' => $order_info['payment_zone_code'],
                'country'   => $order_info['payment_country'],
                'country_code' => $order_info['shipping_iso_code_3']
            );
    
            $data['payment_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));
    
            // Shipping Address
            if ($order_info['shipping_address_format']) {
                $format = $order_info['shipping_address_format'];
            } else {
                $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country_code}';
            }`
    

    Added country_code in both $find and $replace array.