jquery - 如果在 WooCommerce 结帐页面上选中复选框,则更改送货城市字段的值
问题描述
如果选中复选框,我正在尝试为运输城市设置一个值“local-pickup”,同时在设置复选框时隐藏该字段。
当复选框被选中时,我能够隐藏该字段,但无法将字段的值更改为“local-pickup”。字段运输城市是一个选择字段。
这是我的代码:
add_action('woocommerce_after_checkout_form', 'bbloomer_conditionally_hide_show_checkout_field', 9999);
function bbloomer_conditionally_hide_show_checkout_field() {
wc_enqueue_js("
jQuery('#shipping_checkbox').change(function() {
if (this.checked) {
jQuery('#shipping_address_1_field').hide();
jQuery('#shipping_address_2_field').hide();
jQuery('#shipping_city_field').hide();
} else {
jQuery('#shipping_address_1_field').show();
jQuery('#shipping_address_2_field').show();
jQuery('#shipping_city_field').show();
}
}).keyup();
");
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<label class="checkbox" data-required="0">
<input type="checkbox" class="input-checkbox " name="shipping_checkbox" id="shipping_checkbox" value="1">local-pickup?</label>
<select name="shipping_city" id="shipping_city" class="select wc-enhanced-select" data-required="1" autocomplete="address-level2"><option value="" disabled="disabled" selected="selected">select city</option><option value=""></option><option value="city1">city1</option><option value="city2">city2</option><option </select>
谢谢
解决方案
推荐阅读
- itext7 - 如何将 CPS 链接信息添加到法律声明选项卡?
- python - 如何在 Tkinter 中创建字体轮廓
- node.js - 如何防止恶意软件上传以保存网络公共图像?
- laravel - 跨域请求被阻止 Laravel
- excel - 在 Angular 中使用 xlsx - 如何让 excel 自动将日期识别为列中的实际日期?
- python - Tensorflow 网络摄像头对象检测未启动
- php - 用 PHP 生成 Csv - 输出不必要的引号
- ruby-on-rails - 通过 ssh 与 ubuntu 18 连接
- java - 如何修复netbeans中的getrowcount()?
- android-studio - RecylerView to pdf