* Indicates required field.
I want this text to be shown only when customer fills in new address form in one page checkout.
Otherwise if customer chooses address from dropdown this text should be hidden.
Can someone pls help me with this.
Just add this to your onepage checkout billing and shipping template files
<?php if (!$this->customerHasAddresses()): ?>
* Indicates required field.
<?php endif; ?>
I am sure these templates already uses this function customerHasAddresses() to show the new address form or the existing addresses in a dropdown.
Assumption: If a customer is logged in and lands on checkout, the default select option will be the presaved address. If the presaved address is selected, then do not show the Required messaging. If 'New Address' is selected, then show the Required messaging.
<?php if ($this->customerHasAddresses()): ?>
<p class="required" style="display:none;"><?php echo $this->__('* Required Fields') ?></p>
jQuery('#billing-address-select').change(function(){
// All saved addresses have a value, whereas New Address' value is blank
if(jQuery(this).val() == ''){
// Make the Required messaging appear
jQuery( '#co-billing-form .required' ).css( "display", "block" );
} else
// Make the Required messaging disappear
jQuery( '#co-billing-form .required' ).css( "display", "none" );
});
<?php else: ?>
<p class="required"><?php echo $this->__('* Required Fields') ?></p>
<?php endif; ?>
Note: The above has been designed to only work on the Billing Address portion. In order to make this work with the shipping address section as well, duplicate it and swap #co-billing-form
for #co-shipping-form
and #billing-address-select
with #shipping-address-select
.