Hallo,
am just setting up a webshop with Vituemart 3 and joomla 3.9.12. I try to read out the "zip" variable within the current selected address (BT and ST) in the cart . The shopper can select per radio button in the cart between his billing address or a 1 or more further shipping adresses. Each line contains the name of the shipping address, and behind it the zip code. Once the radio button is sleetced the whole address appears underneath the the options. I now need only the zip code of this address and not the full address. I need the zip code to assign it to a new php variable which then will processed further in another skript.
This shall list all availabvle installers in the zip area
The file default_adress.php im com_viruemart/cart/ lists only the whole address .
How do i read the zip variable only out ?
line11:
echo $this->cart->lists['shipTo'];
from the file
<div class="output-shipto">
<?php
if (!class_exists ('VmHtml')) {
require(VMPATH_ADMIN . DS . 'helpers' . DS . 'html.php');
}
if($this->cart->user->virtuemart_user_id==0){
echo vmText::_ ('COM_VIRTUEMART_USER_FORM_ST_SAME_AS_BT');
echo VmHtml::checkbox ('STsameAsBT', $this->cart->STsameAsBT,1,0,'id="STsameAsBTjs" data-dynamic-update=1') . '<br />';
} else if(!empty($this->cart->lists['shipTo'])){
echo $this->cart->lists['shipTo'];
}
if(empty($this->cart->STsameAsBT) and !empty($this->cart->ST) and !empty($this->cart->STaddress['fields'])){ ?>
<div id="output-shipto-display">
<?php
foreach ($this->cart->STaddress['fields'] as $item) {
if($item['name']=='shipto_address_type_name') continue;
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 $item['value'] ?></span>
<?php
} else { ?>
<span class="values"><?php echo $item['value'] ?></span>
<br class="clear"/>
<?php
}
}
}
?>
</div>
<?php
}
or ist it here : ??
$this->cart->STaddress['fields']
Have tried various things but did not succeed :-\
:/
depends WHERE
this below will assign a $my_new_variable to the zip.
foreach ($this->cart->STaddress['fields'] as $item) {
if($item['name']!='zip') continue;
if($item['name']=='zip'){
$my_new_variable=$item['value'] ;
}
}
Hi, tried it out, but doesn't work
Put it right under the if clause to check the item [name] in the foreach loopAnd should echo at least some text, if assigned. On the webiste it doesn't show anything
if(empty($this->cart->STsameAsBT) and !empty($this->cart->ST) and !empty($this->cart->STaddress['fields'])){ ?>
<div id="output-shipto-display">
<?php
foreach ($this->cart->STaddress['fields'] as $item) {
if($item['name']!='zip') continue;
if($item['name']=='zip'){ $zip_var1=$item['value']; echo "zip var1: ".$zip_var1."<br>";};
}
foreach ($this->cart->STaddress['fields'] as $item) {
if($item['name']=='shipto_address_type_name') continue;
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 $item['value'] ?></span>
<?php
} else { ?>
<span class="values"><?php echo $item['value'];
?></span>
<br class="clear"/>
<?php
}
}
} // endof foreach
Insert some debug comments and see if the statements are reached.
Jörgen @ Kreativ Fotografi
yes -- check u are in the correct file..
add <!--- I AM HERE --> in the html and check u can see it