WooCommerce Checkout:如果填充另一个&#x2B,则如何根据需要设置字段;如何使用来自另一个字段的数据自动填充字段
我正在寻找解决问题的解决方案。第一个问题是,如果检查“购买为公司”,我需要根据需要制作现场公司ID。公司复选框的ID是“ Wi_as_company”。我正在尝试将其像Code Bellow一样,但它总是根据需要(也适用于非公司客户)字段“ Billing_company_wi_id”。
add_filter( 'woocommerce_checkout_fields' , 'company_checkbox_and_new_checkout_fields_1', 9999 );
function company_checkbox_and_new_checkout_fields_1( $fields ) {
if (isset($_POST['wi_as_company'])) {
$fields['billing']['billing_company_wi_id']['required'] = false;
} else {
$fields['billing']['billing_company_wi_id']['required'] = true;
}
return $fields;
}
我的第二个问题是我想自动将数据(前8个数字)从一个字段移到另一个字段,然后在之前添加2个字母。一个字段具有这种格式:
12345678-Y-YY
我想将前8个字符移至这样的另一个字段:
XX12345678
我将非常感谢任何建议。
I am looking for solution for my problems in checkout. First problem is that I need to make field company ID as required if field "Buy as company" is checked. ID of company checkbox is "wi_as_company". I am try to make it like code bellow, but it makes field "billing_company_wi_id" always as required (also for non-company customers).
add_filter( 'woocommerce_checkout_fields' , 'company_checkbox_and_new_checkout_fields_1', 9999 );
function company_checkbox_and_new_checkout_fields_1( $fields ) {
if (isset($_POST['wi_as_company'])) {
$fields['billing']['billing_company_wi_id']['required'] = false;
} else {
$fields['billing']['billing_company_wi_id']['required'] = true;
}
return $fields;
}
My second problem is that I want to move data (first 8 numbers) automatically from one field to another one and add 2 letters before. One field have this format:
12345678-Y-YY
and I want to move first 8 characters to another field like this:
XX12345678
I will be very grateful for any suggestions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
第一个问题的答案:如果选中复选框,则需要字段公司 ID。将以下代码写入您的子主题functions.php文件并更改元素的ID:
wi_as_company 是复选框的 ID 并且
如果选中复选框,billing_company_wi_id 是必填字段的 ID
ANSWER FOR FIRST PROBLEM: If checkbox is checked, then field company ID is required. Write code bellow to your child themes functions.php file and change ID of elements:
wi_as_company is ID of checkbox and
billing_company_wi_id is ID of required field if checkbox is checked
第二个问题的答案:更改字段的代码ID和要复制的字符数。在这种情况下,它将从“ billing_company_wi_tax”中复制前8个字符为“ billing_company_wi_vat”,然后在复制文本之前添加字母“ xx”。将此功能插入您的孩子主题functions.php。
ANSWER FOR SECOND PROBLEM: Change in code ID of fields and number of characters to copy. In this case it will copy first 8 characters from "billing_company_wi_tax" to "billing_company_wi_vat" plus it will add letters "XX" before copied text. Insert this function to your child themes functions.php.