Open

Make Ship To the Bill To unless ST exist

Thu May 9, 2013 3:13 am
I hope code is good. Does check for ST and not existant shows BT box instead. Please advise if good code. I tested and works.
		<div class="output-shipto">
		<!-- adding code to change ship to to bill to and back -->
		<?php if (empty($this->cart->STaddress)){ 
 
		foreach($this->cart->BTaddress['fields'] as $item){
 
			if(!empty($item['value'])){
 
				if($item['name']==='agreed'){
 
					$item['value'] =  ($item['value']===0) ? JText::_('COM_VIRTUEMART_USER_FORM_BILLTO_TOS_NO'):JText::_('COM_VIRTUEMART_USER_FORM_BILLTO_TOS_YES');
 
				}
 
				?><!-- span class="titles"><?php echo $item['title'] ?></span -->
 
				<span class="values vm2<?php echo '-'.$item['name'] ?>" ><?php echo $this->escape($item['value']) ?></span>
 
				<?php if ($item['name'] != 'title' and $item['name'] != 'first_name' and $item['name'] != 'middle_name' and $item['name'] != 'zip') { ?>
 
				<br class="clear" />
 
				<?php
 
				}
 
			}
 
		} 
		 } else { 
		if(!class_exists('VmHtml'))require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'html.php');
 
			echo JText::_('COM_VIRTUEMART_USER_FORM_ST_SAME_AS_BT');
 
			echo VmHtml::checkbox('STsameAsBT',$this->cart->STsameAsBT).'<br />';
 
			foreach($this->cart->STaddress['fields'] as $item){
 
				if(!empty($item['value'])){ ?>
 
					<!-- <span class="titles"><?php echo $item['title'] ?></span> -->
 
					<?php
 
					if ($item['name'] == 'first_name' || $item['name'] == 'middle_name' || $item['name'] == 'zip') { ?>
 
						<span class="values<?php echo '-'.$item['name'] ?>" ><?php echo $this->escape($item['value']) ?></span>
 
					<?php } else { ?>
 
						<span class="values" ><?php echo $this->escape($item['value']) ?></span>
 
						<br class="clear" />
 
					<?php
 
					}
 
				}
 
			}
 
		}
 
 		?>	
 
        <!-- Ending my code here -->
Original code
		<?php 
 
		if(empty($this->cart->STaddress['fields'])){
 
			echo JText::sprintf('COM_VIRTUEMART_USER_FORM_EDIT_BILLTO_EXPLAIN',JText::_('COM_VIRTUEMART_USER_FORM_ADD_SHIPTO_LBL') );
 
		} else {
 
			if(!class_exists('VmHtml'))require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'html.php');
 
			echo JText::_('COM_VIRTUEMART_USER_FORM_ST_SAME_AS_BT');
 
			echo VmHtml::checkbox('STsameAsBT',$this->cart->STsameAsBT).'<br />';
 
			foreach($this->cart->STaddress['fields'] as $item){
 
				if(!empty($item['value'])){ ?>
 
					<!-- <span class="titles"><?php echo $item['title'] ?></span> -->
 
					<?php
 
					if ($item['name'] == 'first_name' || $item['name'] == 'middle_name' || $item['name'] == 'zip') { ?>
 
						<span class="values<?php echo '-'.$item['name'] ?>" ><?php echo $this->escape($item['value']) ?></span>
 
					<?php } else { ?>
 
						<span class="values" ><?php echo $this->escape($item['value']) ?></span>
 
						<br class="clear" />
 
					<?php
 
					}
 
				}
 
			}
 
		}
 
 		?>		
I do not like to ask unless I get confused or lost. I love to learn, I just struggle with it sometimes.
The administrator has disabled public write access.