I tried to add a checkbox for a pick-up shipping method, so when the method is chosen, the tickbox appears and need to be validated but when the other shipping method is chosen, I want it to disappear. Currently, it's not getting validation, neither it disappears when the other option is chosen (major problem).
Based on Add a checkbox below a specific shipping method in WooCommerce 3 answer, this is the code I'm using:
add_action( 'woocommerce_after_shipping_rate', 'checkout_shipping_additional_field', 20, 2 );
function checkout_shipping_additional_field( $method, $index )
{
if( $method->get_id() == 'pickup-location-method' ){
echo '<br>
<input type="checkbox" name="shipping_custom_1" id="shipping_custom_1" value="1" class="shipping_method shipping_custom_1">
<label for="shipping_custom_1">I confirm that I'll attend the delivery.</label>';
}
}
Unfortunately, my limited knowledge doesn't allow me to progress with this code further. Could you help me with this, please?