Billing Shipping required fields

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hillhouse
    Mini Mivite

    • Aug 2008
    • 21

    #1

    Billing Shipping required fields

    My client wants to have Billing for main address and if they need to ship to a different address, he doesn't want them to have to fill in email and phone number, but there doesn't seem to be an option to make those required for the billing and not for shipping address also. (at least not via "Customer Fields" in the shop admin)

    I thought making Billing primary and Shipping optional would do that (and control only Billing required fields with the radio buttons), but there has to be nothing filled out in the shipping for the Shipping section to be optional. Otherwise it has the same restrictions as Billing.
  • KNewbrough
    Mivite

    • May 2013
    • 200

    #2
    Re: Billing Shipping required fields

    There is no way with the default software to make a field required for billing and optional for shipping (or vice versa). You can, however, set both of them to optional in the software and then enforce the requirement on one set of fields using JavaScript.

    I've seen this request a few times and it's pretty quick to do so if you'd like you can email [email protected] with your site URL and a link to this forum post and ask for me in the email, I'll set that up for you and paste the code here for the benefit of others in the future with the same request.
    Kyle Newbrough
    Technical Support / Web Developer
    Miva Merchant

    Comment

    • hillhouse
      Mini Mivite

      • Aug 2008
      • 21

      #3
      Re: Billing Shipping required fields

      Thanks! Sounds good.

      Comment

      • KNewbrough
        Mivite

        • May 2013
        • 200

        #4
        Re: Billing Shipping individually required fields

        Here's what I came up with for the benefit of anyone else needing this functionality:

        Code:
        <mvt:if expr="g.Screen IN 'OCST|ACED|ACAD'">
          <script>
            $(function(){
              var reqFields = ['BillEmail','BillPhone'];
              var haltForm;
              $('input[value="Continue"], input[value="Save"]').on('click',function(event){
                $.each(reqFields,function(intVal,theField){
                  var str = $('input[name*='+this+']').val()
                  if (str === ''){
                    $('input[name*='+this+']').css('border','2px solid #f00');
                    haltForm = '1';        
                  };
                });
                if(haltForm === '1'){  
                  event.preventDefault();      
                  haltForm = '0';
                };
              });
            });
          </script>
        </mvt:if>
        This script requires jQuery v1.7 or later on OCST, ACED and ACAD. I'd put it at the bottom of your Global Footer.

        You'll also need to go into your store settings and to the Customer Fields tab and mark each of the fields as Optional. You will then need to visit each of these pages' templates (ACED, ACAD and OCST) and in the Customer Fields tab change the label for each of those fields from <i> to <b> since the software will have changed them to italics since they're optional. Any time you change your Customer Fields settings you will need to re-do that step because the software completely rewrites those tabs.

        If you need to make different fields required you can just modify the list of single-quoted field names in the reqFields array near the top of the script. For example of you wanted to instead make the shipping city, zip and address fields required you'd change the array to "var reqFields = ['ShipCity','ShipZip','ShipAddress1'];".

        This will work with both the old account fields from before PR8 Update 7, as well as the more current ones. You can use the format beginning with "Customer_" (if your store is using those) or omit that part, either way will work.
        Kyle Newbrough
        Technical Support / Web Developer
        Miva Merchant

        Comment

        • hillhouse
          Mini Mivite

          • Aug 2008
          • 21

          #5
          Re: Billing Shipping individually required fields

          Thank you very much!

          Comment

          Working...
          X