php – How to remove billing details on check out page and change the billing details to MailChimp newsletter-ThrowExceptions

Exception or error:

I was just wondering how do you remove the billing details on woocommerce and just go through payment options. I tried following lines of code but the billing details and additional information are still there.

<?php

add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );

function custom_override_checkout_fields( $fields ) {
    unset($fields['billing']['billing_first_name']);
    unset($fields['billing']['billing_last_name']);
    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_last_name']);
    unset($fields['billing']['billing_email']);
    unset($fields['billing']['billing_city']);
    return $fields;
}

Also I’m trying to figure out that instead of billing details can I change MailChimp newsletter.

How to solve:

Depending on the type of products you are selling via a WooCommerce store, sometimes you don’t need the billing and shipping address details on the WooCommerce checkout page.

For example when purchasing a simple virtual product. We just want to send the user to Payment without any hassle.

Base on your requirement you can achieve disable billing address by below code put into functions.php file.

You can modify the checkout page by placing different logic inside a function.

add_action('woocommerce_checkout_init','disable_billing');
function disable_billing($checkout){
  $checkout->checkout_fields['billing']=array();
  return $checkout;
  }

Answer´╝Ü

Ash’s answer is not working for me, but I found that adjusting the hook back to the original one, and simply overriding the checkout fields worked for me.

add_filter( 'woocommerce_checkout_fields' , 'remove_billing_fields_from_checkout' );
function remove_billing_fields_from_checkout( $fields ) {
    $fields[ 'billing' ] = array();
    return $fields;
}

Leave a Reply

Your email address will not be published. Required fields are marked *