【问题标题】:Woocommerce checkout field maxlength, make input number field only (postcode)Woocommerce 结帐字段最大长度,仅输入数字字段(邮政编码)
【发布时间】:2016-01-26 11:09:37
【问题描述】:

我已经为此苦苦挣扎了几天。我想做的是将邮政编码/邮政编码字段限制为 4 个数字。因此,向这些字段添加 maxlengthtype="number"

到目前为止我尝试过的事情:

  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) 一种jQuery方式

(无法发布,由于某种代码格式错误?)

编辑:事实证明,我正在编辑服务器上的旧文件......在编辑正确的文件后,maxlength 更改与之前提供的代码一样工作正常。但是还是有改变输入类型的问题。

我尝试添加$fields['billing']['billing_postcode']['type'] = 'number';,但这似乎出于某种原因一起删除了输入字段。我猜可能是由于一些错误。不确定。

【问题讨论】:

  • 在尝试粘贴 jQuery 时遇到什么代码格式错误? sn-p 是不是太长了?
  • 我不知道。 Stackoverflow 给了我一些格式错误。

标签: php wordpress function woocommerce maxlength


【解决方案1】:

您需要在另一个名为“custom_attributes”的子数组中添加属性,例如:

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

【讨论】:

    猜你喜欢
    • 2016-10-20
    • 2021-11-08
    • 2018-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-26
    相关资源
    最近更新 更多