Add a Company Field to Your Checkout Page (Or Any Other Field)

With the release of Cart66 1.5.1.4, we have included support for adding custom fields to the checkout process. The method for adding in the custom fields is very simple, but a little bit different for each section. You can add in a custom billing field, shipping field, or payment field. To do this, you need to add a custom filter to your themes functions.php file, or create a simple plugin to do this for you. The filter for the billing field looks like this:

The first variable is the name of the filter you are hooking on to. The second variable is the name of your custom function that you want to run that will add your field into the Cart66 checkout process.

The shipping filter looks like this:

And the payment filter looks like this:

You can only add a custom field at the end of each form section, but you can add as many as you like depending on your function.

The custom function needs to include a $value variable that gets passed into the function. If you don’t have this variable, any other custom fields that get added will not work. The $value variable is an array and you will just need to tack on an element to the array and return it. For example:

 


In our example, we have added on a new array with a key of ‘company’. This key is required and must be the same as the slug element defined below.

Following is a list of each element that can be in this array and the intended function.

‘label’ (required) – The label element is what will be displayed on the checkout page, as well as on the receipt and order view section for each individual order.

‘slug’ (required) – The slug should be identical to the array key and is used for the name of the field. This will be used to help validate the field and save the data.

‘type’ (required) – This sets the type of field to be displayed. At this point, the only value allowed is ‘text’.

‘section’ (required) – This option is required in order to set what section you want the saved data to appear in after the order has been submitted. This is usually the same as the filter element, but you can set it however you like. For example, if you are adding a field to the billing section, you would set this to ‘billing’. However, if you wanted the field to be in the payment section after purchase, set this to ‘payment’ even though the original field appears in the billing section.

‘default’ (optional) – This is the default text that you want to appear if any. You can leave this out or set it to an empty string.

‘required’ (required, boolean) – This is a simple validator that sets the field to require a value or not. When set to true, the customer is required to input data. If the field is left empty, the form will kick back an error. When set to false, the customer can submit the form without any information included in this field.

‘validator’ (optional) – This is the name of a custom validator function that you can set to validate the data that is returned. This function must return an array that is similar to the following:

If the validator returns true, you don’t need to have an ‘errors’ element in the returned array.

Following is an example of a custom company field added to the ‘Payment’ section of the checkout form:

Following is an example of a custom validator at work:

Following is a custom company field displayed on the online receipt:

0

This site is documentation for Cart66 Pro which is no longer maintained. View the Cart66 Cloud Documentation.
What Happened to Cart66 Pro?