Woocommerce结帐字段maxlength,仅输入数字字段(邮政编码)

I've been struggling with this for a few days now. What I want to do, it to limit the Postcode/zip fields to 4 numbers. So, to add a maxlength and a type="number" to those fields.

Things I've tried so far:

  1. (functions.php)

    add_filter( 'woocommerce_checkout_fields', 'custom_override_checkout_fields' );
    
    function custom_override_checkout_fields( $fields ) {    
    
      $fields['billing']['postcode']['maxlength'] = 4;    
      return $fields;
    }
    
  2. (functions.php) a jQuery way

(Unable to post, due some sort of code format error?)

EDIT: As it turned out, i was editing the old files on the server ... after editing the right one, the maxlength change works fine as the previously supplied code. But there is still the issue of changing the input type.

i tried adding $fields['billing']['billing_postcode']['type'] = 'number'; but that seems to REMOVE the input field all together for some reason. Possibly due to some error i guess. Not sure.

You'll need to add the attributes in a further subarray called 'custom_attributes', e.g.:

$fields['billing']['postcode']['custom_attributes']['maxlength'] = 4;