Answer the question
In order to leave comments, you need to log in
How to implement a checkbox that hides the fields on the checkout page?
Task:
1. Show either field1 or field2.
2. When submitting, do not send a hidden field.
If checked:
Поле1
else:
Поле2
add_action( 'woocommerce_after_checkout_form', 'custom_hide_show_field', 6);
function custom_hide_show_field
{
?>
<script type="text/javascript">
$('input[type=checkbox]').change(function(){
if(this.checked) {
$('.field1').hide();
$('.field2').show();
} else {
$('.field1').show();
$('.field2').hide();
}
});
</script>
<?php
}
Answer the question
In order to leave comments, you need to log in
What if
?
well, or the value is first into a variable - and then cleared. And when castling - we change places?
ps I remember, if the field is disabled - then they are not transferred to the post request - as option 2 $('.field1').empty().hide();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question