Verzendadres verwijderen uit je WooCommerce shop

Soms wil je liever geen adressen van klanten van je WooCommerce webshop. Bijvoorbeeld als je gratis digitale producten aanbied als download. Hoe kun je nu zorgen dat je webshop dan alleen vraagt om een Naam + email i.pv. een naam, straat, postcode, land? Onderstaande code helpt je.

Stap 1: Installeer een Child theme voor je WordPress site als je dat niet al hebt gedaan. Elk goed thema heeft een Child theme. Hierin maak je aanpassingen qua stijl en functie om te voorkomen dat je aanpassingen overschreven worden als het thema een update krijgt. (Iets dat wel zou gebeuren als je in het gewone actieve thema werkt).

Stap 2: Ga naar Dashboard > Weergave > Thema’s bewerken

Stap 4: Selecteer je ‘functions.php’ aan de rechterkant en plak de volgende code:


add_filter( 'woocommerce_checkout_fields' , 'woo_remove_billing_checkout_fields' ); /** * Remove unwanted checkout fields * * @return $fields array */ function woo_remove_billing_checkout_fields( $fields ) { if( woo_cart_virtual_downloadable_product_only() == true ) { unset($fields['billing']['billing_company']); unset($fields['billing']['billing_address_1']); unset($fields['billing']['billing_address_2']); unset($fields['billing']['billing_city']); unset($fields['billing']['billing_postcode']); unset($fields['billing']['billing_country']); unset($fields['billing']['billing_state']); unset($fields['billing']['billing_phone']); unset($fields['order']['order_comments']); unset($fields['billing']['billing_address_2']); unset($fields['billing']['billing_postcode']); unset($fields['billing']['billing_company']); unset($fields['billing']['billing_city']); } return $fields; } /** * Check if the cart contains virtual/downloadable product only * * @return bool */ function woo_cart_virtual_downloadable_product_only() { global $woocommerce; // By default, virtual/downloadable product only $virtual_downloadable_products_only = true; // Get all products in cart $products = $woocommerce->cart->get_cart(); // Loop through cart products foreach( $products as $product ) { // Get product ID $product_id = $product['product_id']; // is variation downloadable $is_downloadable = $product['data']->downloadable; // is variation virtual $is_virtual = $product['data']->virtual ; // Update $virtual_downloadable_products_only if product is not virtual or downloadable and exit loop if( $is_virtual == 'no' && $is_downloadable == 'no' ){ $virtual_downloadable_products_only = false; break; } } return $virtual_downloadable_products_only; }

Bron: Remove the billing address fields for virtual orders in WooCommerce