Need help with validating billing fields in woocommerce

Hi experts,

Need help with validating billing fields in woocommerce, i.e. address field need to limit to 55 characters.  The reason for this is because of cybersource payment gateway, getting errors when a user enters details more than 55 characters.  The last user entered 111 characters, and caused an error and the transaction not to go through.  The site is www.bookworldzambia.com

Thanks
Kasonde NeddyDesigner & DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
What would you want to have happen if the user entered a long data field?  If you can describe the response/condition I am sure we can help make it happen.
0
Kasonde NeddyDesigner & DeveloperAuthor Commented:
Hi Ray,

Thanks for the response...when user enters long data field, the payment is not going through inside the payment gateway.  See correspondence below:

Unfortunately increasing the size of the fields will not be possible at this stage. However, there are additional fields that can be used e.g. for addresses there are two fields that can be used, address_line1 and address_line2. The major issue is in the way the data is collected from your end for instance a customer used an address in this format when making an order;

 

Company: Immigration Livingstone Airport Attention Francis Lungu

Address_1: Livingstone Airport Immigration officesHarry Mwaanga Nkumbula (Livingstone Airport) Main Airport building

Address_2: the field is blank

City: Livingstone

Postal Code: LIVINGSTONE

 

Your site already has a second address field that can be utilized in an event the address is longer than 60 characters of which when the two fields are utilized the total sum of characters comes to a 120 in all. Using the same example above, the address can completed as follows;

 

Name: Attention Francis Lungu

Company: Immigration Livingstone Airport

Address_1: Livingstone Airport Immigration offices

Address_2: Harry Mwaanga Nkumbula Main Airport building

City: Livingstone

Postal Code: 12345

 

Customers will also need to be educated on how to complete their addresses by way of using placeholders or providing an example on the site itself when completing the fields.
0
Kasonde NeddyDesigner & DeveloperAuthor Commented:
The above response was from barclays bank person running cybersource payment gateway
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Kasonde NeddyDesigner & DeveloperAuthor Commented:
After checking further, the following issues have been identified;

 

bill_to_address_line1: this field only allows a maximum of 60 Alpha Numeric Punctuation string but what was feed in was 105 character string

bill_to_address_postal_code: this field only allows a maximum of 10 Alpha Numeric Punctuation string but what was feed in was 11 character string

bill_to_company_name: this field only allows a maximum of 40 Alpha Numeric Punctuation string but what was feed in was 55 character string
The data that is being passed forward to CyberSource needs to match the character set.
0
Kasonde NeddyDesigner & DeveloperAuthor Commented:
See attached files too...hope you will be able to help!
Order-Status-1-.xlsx
Reason-Codes-1-.xlsx
0
Ray PaseurCommented:
There may be a lot more to it than this, but it's a start.  Please see:
http://iconoun.com/demo/temp_kasondeneddy.php

In this example we test the length of the form input.  If it goes over 4 characters (choose whatever makes sense for your work), we hide the submit button and display an explanatory message.  If the client shortens the input, the message disappears and the submit button comes back into view.

<!DOCTYPE html>
<html dir="ltr" lang="en-US">
<head>

<!--
   SEE http://www.experts-exchange.com/Web_Development/Blogs/WordPress/Q_28507039.html#a40290842
   SHOW HOW TO HIDE THE SUBMIT BUTTON IF THE INPUT DATA IS TOO BIG
-->

<meta charset="utf-8" />
<meta name="robots" content="noindex, nofollow" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
$(document).ready(function(){
    $("#addr").keyup(function(){
        len = $("#addr").val().length;
        if (len > 4){
            $("#subm").hide();
            $("#errr").html("Too Long!");
        }
        if (len < 5){
            $("#subm").show();
            $("#errr").html("");
        }
    });
});
</script>

<title>HTML5 Page With jQuery Input Length Test</title>
</head>
<body>

<form>
<input id="addr">
<input id="subm" type="submit" value="OK, Go!" />
<div id="errr"></div>
</form>

</body>
</html>

Open in new window

0
Kasonde NeddyDesigner & DeveloperAuthor Commented:
Thanks so much for this Ray, looking at it now and will respond shortly
0
Kasonde NeddyDesigner & DeveloperAuthor Commented:
Im trying to find where to implement this inside woocommerce...got the idea right!
0
Kasonde NeddyDesigner & DeveloperAuthor Commented:
Wow..they is a lot more... I ve copied the <div id="errr"></div> inside form-checkout.php in woocommerce plugin, can be seen at:

// filter hook for include new pages inside the payment method
$get_checkout_url = apply_filters( 'woocommerce_get_checkout_url', WC()->cart->get_checkout_url() ); ?>

line 27-28:<form name="checkout" method="post" class="checkout" action="<?php echo esc_url( $get_checkout_url ); ?>">
    <div id="errr"></div>

and copied the following code into checkout.js ....see below...

jQuery( function( $ ) {

      $.blockUI.defaults.overlayCSS.cursor = 'default';
      
      // wc_checkout_params is required to continue, ensure the object exists
      if ( typeof wc_checkout_params === 'undefined' )
            return false;

      var updateTimer,
            dirtyInput = false,
            xhr;
      $("#billing_address_1").keyup(function(){
        len = $("#billing_address_1").val().length;
        if (len > 4){
            $("#place_order").hide();
            $("#errr").html("Too Long!");
        }
        if (len < 5){
            $("#place_order").show();
            $("#errr").html("");
        }
    });


Does not seem to be working, but something happens when entering info, but the place order button not hiding...running a localhost woocommerce plugin install ...and testing..Help much appreciated..I am sure I am on the right path.  I ll need the errr text to appear next to the field, but not sure why it is not appearing....
0
eemitCommented:
Try this (copy this to your child theme's functions.php):
add_filter('woocommerce_process_myaccount_field_billing_address_1', 'yourprefix_process_myaccount_address_fields' );
add_filter('woocommerce_process_myaccount_field_billing_address_2', 'yourprefix_process_myaccount_address_fields' );
add_filter('woocommerce_process_myaccount_field_shipping_address_1', 'yourprefix_process_myaccount_address_fields' );
add_filter('woocommerce_process_myaccount_field_shipping_address_2', 'yourprefix_process_myaccount_address_fields' );
function yourprefix_process_myaccount_address_fields( $address_field ) {
	if ( strlen( $address_field ) > 55 ) {
		wc_add_notice( __( 'Please enter an adress line < 55 chars.', 'woocommerce' ), 'error' );
	}

	return $address_field;
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Kasonde NeddyDesigner & DeveloperAuthor Commented:
Exactly what I needed to get done.  Thanks for the help and sorry for closing this late, I am not receiving notifications via email from EE
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
WordPress

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.