Dears,
i’m using snippet plugin to add my code to my ecommerace project , i have pickup and delivery plugin in my delivery option , what i’m trying to do is , once i select pickup option , customer address information fields will be hide which it is not logical to keep it appear and mandatory if pickup from restaurant selected.
i tried to add some other var and some of them works fine and other still appear after loading the page ( before loading and selecting the pickup they are disappear ( as an example the street ) and after loading street return and still appear
https://www.order.ramadaencorekuwait.com/checkout-2/
please let me know if there any issue with the code
add_action('wp_footer', 'custom_checkout_js_script');
function custom_checkout_js_script() {
if( is_checkout() && ! is_wc_endpoint_url() ) :
?>
<script language="javascript">
jQuery( function($){
var a = 'input[name="pi_delivery_type"]:checked',
b = 'input[name="billing_address_4"]';
var d = 'input[name="billing_address_3"]';
var f = 'input[name="billing_avenue"]';
var z = 'input[name="billing_address_2"]';
var s = 'input[name="select2-billing_state-container"]';
// Custom function that show hide specific field, based on radio input value
function showHideField( value, field ){
if ( value === 'pickup' ) {
$(field).parent().parent().hide();
} else {
$(field).parent().parent().show();
}
}
// On start after DOM is loaded
showHideField( $(a).val(), b );
showHideField( $(a).val(), d );
showHideField( $(a).val(), f );
showHideField( $(a).val(), z );
showHideField( $(a).val(), s );
// On radio button change live event
$('form.woocommerce-checkout').on('change', a, function() {
showHideField( $(this).val(), b );
showHideField( $(this).val(), d );
showHideField( $(this).val(), f );
showHideField( $(this).val(), z );
showHideField( $(this).val(), s );
});
});
</script>
<?php
endif;
}
2
Answers
It might be simpler to assign a class to b, d, f, z and s. If you’ve already defined ‘a’, then you could do something like:
Try the following code that disables the submit form everywhere when the delivery method is local pickup.
You should replace (28): "local_pickup:28" with the id of your shipping method.