根据Woocommerce结帐中的复选框显示隐藏订单注释字段 [英] Show hide Order notes field based on a checkbox in Woocommerce checkout
问题描述
在Woocommerce结帐页面中,有一个到不同地址的发货"复选框,我希望在选中该复选框时隐藏order_comments
字段(订购说明).如果再次取消选中该复选框,则order_comments
字段应该可见(未隐藏).
In Woocommerce checkout page there is a "ship-to-different-address" checkbox and I would like when it is checked, to hide order_comments
field (Order notes). If the checkbox is unchecked back again, order_comments
field should be visible (unhidden).
在functions.php中有可能吗?
Is this possible in functions.php?
推荐答案
以下代码将在选中送货至其他地址"复选框时隐藏订单注释"部分字段,反之亦然:
The following code will hide Order notes section field when "ship-to-different-address" checkbox is checked and vice versa:
add_action( 'wp_footer', 'checkout_custom_script_js');
function checkout_custom_script_js() {
// Only on front-end and checkout page
if( is_checkout() && ! is_wc_endpoint_url() ) :
?>
<script>
jQuery(function($){
$('form.checkout').on( 'change', '#ship-to-different-address-checkbox', function(){
if( $(this).prop('checked') === true )
$('#order_comments_field').hide(); // Show
else
$('#order_comments_field').show(); // Hide
})
});
</script>
<?php
endif;
}
代码位于活动子主题(或活动主题)的function.php文件上.经过测试,可以正常工作.
Code goes on function.php file of your active child theme (or active theme). Tested and works.
这篇关于根据Woocommerce结帐中的复选框显示隐藏订单注释字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!