News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Change order of Country in Confirmation Email

Started by microtribe, October 28, 2015, 01:48:54 AM

Previous topic - Next topic

microtribe

I'd like to change the order of country in the confirmation email. And recommend that the ability to change the order, and remove or hide elements of the confirmation email be built into VM.

Here's the code I found for the confirmation email template, which doesn't show the order of fields. And I can't find the file which contains the base code/functions for displaying the Billing and Shipping address. Where I can find that to change it?

<?php
      if(!empty($BTuserFields)){
         foreach ($BTuserFields['fields'] as $userField) {
            if (!empty($userField['value']) && $userField['type'] != 'delimiter' && $userField['type'] != 'hidden') {
               $value = empty($userField['value']) ? '' : $userField['value'];
               echo '<span>'.$this->escape($value).'</span>';
               if ($userField['name'] != 'title' && $userField['name'] != 'first_name' && $userField['name'] != 'middle_name' && $userField['name'] != 'zip') {
                  echo '<br>';
               }
               else{
                  echo ' ';
               }
            }
         }
      }
      
       ?>

AH

The sequence of the address elements are based on the settings that are used to display that information in the customer checkout.

If this sequence is not what you require in the customer printouts (including emails) you can create an override to achieve this:-

the details for this can be created in an override to:-

templates/YOUR TEMPLATE/html/com_virtuemart/invoice/mail_html_shopperaddresses.php

The sample code has been posted somewhere else in the VM forums - but just in case - I have posted what I use in VM3


<?php
/**
 *
 * Layout for the order email
 * shows the chosen adresses of the shopper
 * taken from the stored order
 *
 * @package VirtueMart
 * @subpackage Order
 * @author Max Milbers,   Valerie Isaksen
 *
 * @link http://www.virtuemart.net
 * @copyright Copyright (c) 2004 - 2010 VirtueMart Team. All rights reserved.
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
 * VirtueMart is free software. This version may have been modified pursuant
 * to the GNU General Public License, and as distributed it includes or
 * is derivative of works licensed under the GNU General Public License or
 * other free or open source software licenses.
 *
 */
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');
//quorvia sequence of address that may differ from the input fields
$addressBTOrder = array('first_name''last_name{br}''email{br}''company{br}','address_1{br}''address_2{br}''city{br}''county{br}''zip{br}''virtuemart_country_id{br}''phone_1{br}');
$addressSTOrder = array('first_name''last_name{br}''company{br}','address_1{br}''address_2{br}''city{br}''county{br}''zip{br}''virtuemart_country_id{br}''phone_1{br}');
?>

<table class="html-email" cellspacing="0" cellpadding="0" border="0" width="100%">
    <tr  >
        <th width="50%">
            <?php echo vmText::_('COM_VIRTUEMART_USER_FORM_BILLTO_LBL'); ?>
        </th>
        <th width="50%" >
            <?php echo vmText::_('COM_VIRTUEMART_USER_FORM_SHIPTO_LBL'); ?>
        </th>
    </tr>
    <tr>
        <td valign="top" width="50%">
            <?php
            
foreach ($addressBTOrder as $fieldname) {
                
$fieldinfo explode('{',$fieldname);
                if (!empty(
$this->userfields['fields'][$fieldinfo[0]]['value'])) { ?>

                    <span class="values vm2<?php echo '-' $this->userfields['fields'][$fieldinfo[0]]['name'?>" ><?php echo $this->escape($this->userfields['fields'][$fieldinfo[0]]['value']) ?></span> <?php
                    
if (isset($fieldinfo[1]) && $fieldinfo[1] == 'br}') { ?>

                        <br class="clear" /> <?php
                    
}
                }
            }
            
?>

        </td>
        <td valign="top" width="50%">
            <?php
            
foreach ($addressSTOrder as $fieldname) {
                
$fieldinfo explode('{',$fieldname);
                if (!empty(
$this->shipmentfields['fields'][$fieldinfo[0]]['value'])) { ?>

                    <span class="values vm2<?php echo '-' $this->shipmentfields['fields'][$fieldinfo[0]]['name'?>" ><?php echo $this->escape($this->shipmentfields['fields'][$fieldinfo[0]]['value']) ?></span> <?php
                    
if (isset($fieldinfo[1]) && $fieldinfo[1] == 'br}') { ?>

                        <br class="clear" /> <?php
                    
}
                }
            }
            
?>

        </td>
    </tr>
</table>


If you want the order to change on printed invoices then you also have to make changes in other files or create your own function.
Regards
A

Joomla 4.4.5
php 8.1

jenkinhill

Re-ordering the shopper fields  (on the shopper fields tab) changes the displayed sequence for some templates.
Kelvyn
Lowestoft, Suffolk, UK

Retired from forum life November 2023

Please mention your VirtueMart, Joomla and PHP versions when asking a question in this forum

AH

#3
Yes Jenkin - the shopper field sequence is used to determine the view/print sequence

However, the business challenge is that the sequence required for checkout may not be the same as that required for order/email printing.

example:-

Checkout may require that the Country  / ZIP is completed before other address fields

However, it is not expected that the country would appear first in an address block on an invoice / email confirmation.
Regards
A

Joomla 4.4.5
php 8.1

PRO



Here is my order email codes
I added comments so you can see what it does
I formatted mine in a way that I just copy & paste it into quickbooks
For example
City,State Zip


If you want to skip a field, just look at this line
      if ($field['name']=='virtuemart_country_id') continue;



  foreach ($this->shipmentfields['fields'] as $field) {
         if (!empty($field['value'])) {
                      /// skip country id
      if ($field['name']=='virtuemart_country_id') continue;
                    /// remove the 1 in front of the phone number
            if ($field['name']=='phone_1') {$field['value'] = ltrim($field['value'], '1');
                     ///  remove dashes from phone number
            $field['value'] = str_replace( '-', '.', $field['value'] );}
                    /// I dont know if this is still needed, but this displays the 2 state code instead of the state name.
                     ///   for example   Florida   to FL
            if ($field['name']=='virtuemart_state_id'){$stateId= shopfunctions::getStateIDByName ($field['value']);
         $field['value'] =shopfunctions::getStateByID ($stateId, 'state_2_code');}
         ?>
                    <?php
                       /// This code displays the field
                       ?>
              <span class="values vm2<?php echo '-' . $field['name'] ?>" ><?php echo $this->escape($field['value']) ?></span>
                   
         <?php
                       /// ONLY the fields listed in this if statement will have a "break" after them.
                       if (($field['name'] == 'first_name') OR ($field['name'] =='zip') OR ($field['name'] =='company') OR ($field['name']=='phone_1') OR ($field['name']=='email') OR ($field['name']=='address_1') OR ($field['name']=='address_2')  ) { ?>
             <br class="clear" />
             <?php
         }
                          //// This adds a comma after the city
         if ($field['name']=='city'){echo ' ,';}
          }
       }

microtribe

I found that Interamind Email Manager allows you to customize the order confirmation template and change the order of the fields using tags. Was never able to track down the code in VM that dictates the order of the fields in the address, but the component is a better solution anyway. Thanks.