Customizing Country and Address Fields in SureCart

SureCart provides hooks that allow you to customize the default country fields and country-specific fields used in the checkout and address forms. This guide will show you how to use the surecart_default_country_fields and surecart_country_fields hooks to modify these fields.


Hook -surecart_default_country_fields

This filter hook allows you to modify the default country fields used by SureCart.

Column NamePriority
(Lower will be shown first)
Default Label
name30Name or Company Name
country40Country
address_150Address
address_260Address Line 2
city70City
state80State/Province/Region
postcode90Postal Code/Zip

Usage:

add_filter( 'surecart_default_country_fields', function( $fields ) {
    // Modify the default country fields here.
    return $fields;
}, 10, 1 );

Real life Example:

Change Name / Company name column's label to Full Name

add_filter( 'surecart_default_country_fields', function( $fields ) {
    // Change the label for the 'name' field.
    foreach ( $fields as &$field ) {
        if ( $field['name'] === 'name' ) {
            $field['label'] = __( 'Full Name', 'your-plugin-textdomain' );
        }
    }
    return $fields;
}, 10, 1 );

Hook - surecart_country_fields

This filter hook allows you to modify the country-specific fields used by SureCart.

Usage:

add_filter( 'surecart_country_fields', function( $fields ) {
    // Modify the country-specific fields here.
    return $fields;
}, 10, 1 );

Real life Example:

Changing the Label for the 'state' Field for the United States (US):

add_filter( 'surecart_country_fields', function( $fields ) {
    if ( isset( $fields['US'] ) && isset( $fields['US']['state'] ) ) {
        $fields['US']['state']['label'] = __( 'State/Province', 'your-plugin-text-domain' );
    }
    return $fields;
}, 10, 1 );

By using these hooks, you can customize the labels of the address fields used by SureCart to fit your specific requirements.