0

* 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.

2 Answers 2

0

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.

6
  • I need this text to be shown only when the form is filled and not when the select box is shown. :(
    – Swetha
    Commented Sep 26, 2015 at 11:03
  • Can u pls tel me someone condition instead of customerHasAddresses because even if a customer already has an address they can add new address.
    – Swetha
    Commented Sep 26, 2015 at 11:05
  • Just edited my answer its supposed to be if (!$this->customerHasAddresses()):
    – Haijerome
    Commented Sep 26, 2015 at 11:05
  • why cant you write a script to check whether the customer selects the "add new address" option to display this message or not ?
    – Haijerome
    Commented Sep 26, 2015 at 11:07
  • This also doesnt work.. If customer already has saved address and if they click on add new address this text will not show. :(
    – Swetha
    Commented Sep 26, 2015 at 11:08
0

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.