[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2197
  • Last Modified:

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

  • 8
  • 2
2 Solutions
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.
kasondeneddyAuthor 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



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.
kasondeneddyAuthor Commented:
The above response was from barclays bank person running cybersource payment gateway
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

kasondeneddyAuthor 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.
kasondeneddyAuthor Commented:
See attached files too...hope you will be able to help!
Ray PaseurCommented:
There may be a lot more to it than this, but it's a start.  Please see:

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">

   SEE http://www.experts-exchange.com/Web_Development/Blogs/WordPress/Q_28507039.html#a40290842

<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>
        len = $("#addr").val().length;
        if (len > 4){
            $("#errr").html("Too Long!");
        if (len < 5){

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

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


Open in new window

kasondeneddyAuthor Commented:
Thanks so much for this Ray, looking at it now and will respond shortly
kasondeneddyAuthor Commented:
Im trying to find where to implement this inside woocommerce...got the idea right!
kasondeneddyAuthor 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,
        len = $("#billing_address_1").val().length;
        if (len > 4){
            $("#errr").html("Too Long!");
        if (len < 5){

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

kasondeneddyAuthor 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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 8
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now