Change characters of checkout field in WooCommerce to UPPERCASE

Viewed 136

How can I change the characters of the checkout field in WooCommerce to uppercase? I have changed it by CSS (text-transform) but it is changing letters to uppercase only in frontend. When customers write lowercase characters to a field, then it is sent to the system with lowercase. ID of field is "billing_company_wi_vat". I will be grateful for any suggestion.

I found on the internet something like this but I don't know how to use it.

var upper = text.toUpperCase();
1 Answers
function wc_checkout_alter_field_input() {
    if (is_checkout()):
        if (!wp_script_is('jquery', 'done')) {
            wp_enqueue_script('jquery');
        }
        wp_add_inline_script('wc-checkout', 'jQuery(document).ready(function($){ $("#billing_company_wi_vat").keyup(function() { this.value = this.value.toUpperCase();});});');
    endif;
}

add_action('wp_enqueue_scripts', 'wc_checkout_alter_field_input');

Add this to your active theme functions.php file. The function wp_add_inline_script allows to add extra code to a registered script. wc-checkout-js will be rendered in the checkout page by WooCommerce. so we can add some additional JS through that ID wc-checkout

Related