Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php WooCommerce-限制购物车页面(而不是结账/账户页面)上的邮政编码字符限制_Php_Wordpress_Woocommerce - Fatal编程技术网

Php WooCommerce-限制购物车页面(而不是结账/账户页面)上的邮政编码字符限制

Php WooCommerce-限制购物车页面(而不是结账/账户页面)上的邮政编码字符限制,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,因此,我可以在my functions.php中使用以下代码,将用户帐户页面和结账页面上的发货/账单信息的邮政编码长度限制为5: function my_wc_custom_billing_fields( $fields ) { $fields['billing_postcode']['maxlength'] = 5; return $fields; } add_filter( 'woocommerce_billing_fields', 'my_wc_custom_billi

因此,我可以在my functions.php中使用以下代码,将用户帐户页面和结账页面上的发货/账单信息的邮政编码长度限制为5:

function my_wc_custom_billing_fields( $fields ) {
    $fields['billing_postcode']['maxlength'] = 5;

    return $fields;
}

add_filter( 'woocommerce_billing_fields', 'my_wc_custom_billing_fields' );

function my_wc_custom_shipping_fields( $fields ) {
    $fields['shipping_postcode']['maxlength'] = 5;

    return $fields;
}

add_filter( 'woocommerce_shipping_fields', 'my_wc_custom_shipping_fields' );
但是,我仍然能够在购物车页面的邮政编码框中输入超过限制的内容。您可以在购物车页面上更改您的地址,如果您在键入超过5位数字后单击“转到结帐”,它将允许表单在结帐页面上填写这些额外的数字。我希望购物车页面上的邮政编码框与其他页面上的邮政编码框一样工作

感谢您抽出时间阅读本文。我希望不久能收到某人的来信

------->编辑:找到了! 我没有在functions.php中创建过滤器,而是直接编辑了woocommerce/templates/cart/shipping-calculator.php文件

在这段代码中:

<?php if ( apply_filters( 'woocommerce_shipping_calculator_enable_postcode', true ) ) : ?>
            <p class="form-row form-row-wide" id="calc_shipping_postcode_field">
                <input type="text" class="input-text" value="<?php echo esc_attr( WC()->customer->get_shipping_postcode() ); ?>" placeholder="<?php esc_attr_e( 'Postcode / ZIP', 'woocommerce' ); ?>" name="calc_shipping_postcode" id="calc_shipping_postcode" />
            </p>
        <?php endif; ?>


我刚想出来!我没有在函数中创建一个过滤器,而是直接在Templates/cart/文件夹中编辑WooCommerce的“shipping calculator.php”中的代码。请不要将解决方案添加到问题本身中。相反,从问题中删除解决方案,并使用答案部分将其作为答案发布,然后接受它。回答你自己的问题没关系!我刚想出来!我没有在函数中创建一个过滤器,而是直接在Templates/cart/文件夹中编辑WooCommerce的“shipping calculator.php”中的代码。请不要将解决方案添加到问题本身中。相反,从问题中删除解决方案,并使用答案部分将其作为答案发布,然后接受它。回答你自己的问题没关系!
<input type="text" class="input-text" maxlength="5" value="