How to add a required custom field in cash on delivery gateway
-
I added a custom field in woocommerce payment gateway (cash on delivery) and I want it to be required, so I add the following piece of code in my child theme/woocommerce/checkout/payment-method.php.
<?php if ( $gateway->id == "cod" ) : ?> <div class="payment_box payment_method_<?php echo $gateway->id; ?>" <?php if ( ! $gateway->chosen ) : ?>style="display:none;"<?php endif; ?>> <?php $gateway->payment_fields(); ?> </br> <label>Which time is best for delivery?</label></br> <input type="text" name='cod_custom_field' required></br> </div>
but then the field becomes required for the other payment gateways as well!. So how to make the cod custom filed required without effecting other gateways.
I tried this code also, but I got the same result!
<div class="payment_box payment_method_<?php echo $gateway->id; ?>" <?php if ( ! $gateway->chosen ) : ?>style="display:none;"<?php endif; ?>> <?php $gateway->payment_fields(); ?> </br> <label>Which time is best for delivery?</label></br> <input type="text" name='cod_custom_field' <?php echo ($gateway->id=='cod') ? 'required' : ''; ?>></br> </div>
Please help in this or guide me to activate the shipping info on just COD option.
Thanks
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘How to add a required custom field in cash on delivery gateway’ is closed to new replies.