WordPress – Woocommerce – Supprimer des champs ou les rendre obligatoires ou non – Remove Fields from Woocommerce checkout page or make some fields mandatory or not

Supprimer des champs dans les pages de checkout woocommerce et de modification d’adresses de livraison et facturation

Remove fields in woocommerce checkout and on billing and shipping addresses edition pages

functions.php

Ajouter et adapter le code suivant.
Add and adapt the following code
/* Remove Woocommerce User Fields */
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
add_filter( 'woocommerce_billing_fields' , 'custom_override_billing_fields' );
add_filter( 'woocommerce_shipping_fields' , 'custom_override_shipping_fields' );
function custom_override_checkout_fields( $fields ) {
unset($fields['billing']['billing_state']);
unset($fields['billing']['billing_country']);
unset($fields['billing']['billing_company']);
unset($fields['billing']['billing_address_1']);
unset($fields['billing']['billing_address_2']);
unset($fields['billing']['billing_phone']);
unset($fields['billing']['billing_postcode']);
unset($fields['billing']['billing_city']);
unset($fields['shipping']['shipping_state']);
unset($fields['shipping']['shipping_country']);
unset($fields['shipping']['shipping_company']);
unset($fields['shipping']['shipping_address_1']);
unset($fields['shipping']['shipping_address_2']);
unset($fields['shipping']['shipping_phone']);
unset($fields['shipping']['shipping_postcode']);
unset($fields['shipping']['shipping_city']);
return $fields;
}
function custom_override_billing_fields( $fields ) {
unset($fields['billing_state']);
unset($fields['billing_country']);
unset($fields['billing_company']);
unset($fields['billing_address_1']);
unset($fields['billing_address_2']);
unset($fields['billing_phone']);
unset($fields['billing_postcode']);
unset($fields['billing_city']);
return $fields;
}
function custom_override_shipping_fields( $fields ) {
unset($fields['shipping_state']);
unset($fields['shipping_country']);
unset($fields['shipping_company']);
unset($fields['shipping_address_1']);
unset($fields['shipping_address_2']);
unset($fields['shipping_phone']);
unset($fields['shipping_postcode']);
unset($fields['shipping_city']);
return $fields;
}

Rendre des champs optionnels ou obligatoires dans la page de checkout woocommerce

Make some fields optionnal or required on woocommerce checkout page

functions.php

Ajouter et adapter le code suivant. Pour rendre ces champs optionnels.
Add and adapt the following code to make some fields optionnal
/* Make billing fields not required in checkout */
add_filter( 'woocommerce_billing_fields', 'wc_npr_filter_billing_fields', 10, 1 );
function wc_npr_filter_billing_fields( $address_fields ) {
$address_fields['billing_first_name']['required'] = false;
$address_fields['billing_last_name']['required'] = false;
$address_fields['billing_company']['required'] = false;
$address_fields['billing_address_1']['required'] = false;
$address_fields['billing_address_2']['required'] = false;
$address_fields['billing_phone']['required'] = false;
$address_fields['billing_city']['required'] = false;
$address_fields['billing_postcode']['required'] = false;
$address_fields['billing_state']['required'] = false;
$address_fields['billing_country']['required'] = false;
return $address_fields;
}

/* Make shipping fields not required in checkout */
add_filter( 'woocommerce_shipping_fields', 'wc_npr_filter_shipping_fields', 10, 1 );
function wc_npr_filter_shipping_fields( $address_fields ) {
$address_fields['shipping_first_name']['required'] = false;
$address_fields['shipping_last_name']['required'] = false;
$address_fields['shipping_company']['required'] = false;
$address_fields['shipping_address_1']['required'] = false;
$address_fields['shipping_address_2']['required'] = false;
$address_fields['shipping_phone']['required'] = false;
$address_fields['shipping_city']['required'] = false;
$address_fields['shipping_postcode']['required'] = false;
$address_fields['shipping_state']['required'] = false;
$address_fields['shipping_country']['required'] = false;
return $address_fields;
}

Pour les rendre obligatoire, changez juste false en true dans le code précédent. Un peu comme ceci…
To make some fields mandatory, just change false to true in the previous code. a bit like this…
/* force mandatory fields in checkout - NIF */
add_filter( 'woocommerce_billing_fields', 'wc_dbs_filter_company', 10, 1 );
function wc_dbs_filter_company( $address_fields ) {
$address_fields['billing_company']['required'] = true;
return $address_fields;
}

Author: bejisan

Share This Post On