December 28, 2024
1 min read
Essential Code Snippet For Web Developers

Woocommerce has a lot of field in billing and shipping details. you can use a plugin to add or remove woocommerce checkout fields, it but some people like me try to not use the plugin as much as possible time.

So, let just put the code on your functions.php and comment or remove those line that you need to show on woocommerce checkout page. For example, I activate the email field by comment out unset($fields[‘billing’][‘billing_email’]);

theme functions.php
add_filter( 'woocommerce_checkout_fields' , 'custom_remove_woo_checkout_fields' );
 
function custom_remove_woo_checkout_fields( $fields ) {

    // remove billing 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['billing']['billing_email']);
   
    // remove shipping fields 
    unset($fields['shipping']['shipping_first_name']);    
    unset($fields['shipping']['shipping_last_name']);  
    unset($fields['shipping']['shipping_company']);
    unset($fields['shipping']['shipping_address_1']);
    unset($fields['shipping']['shipping_address_2']);
    unset($fields['shipping']['shipping_city']);
    unset($fields['shipping']['shipping_postcode']);
    unset($fields['shipping']['shipping_country']);
    unset($fields['shipping']['shipping_state']);
    
    // remove order comment fields
    unset($fields['order']['order_comments']);
    
    return $fields;
}

It just simple woocommerce filter hook that work great. Any question comment below, Enjoy 😍

Leave a Reply

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

WordPress Ajax Search without plugin [ Easy ]

WordPress Ajax Search without plugin. Fully custom code work with woocommerce as well

JS fetch post API Data in 5 min simple way

js fetch post API is very simple way. some line of Javascript code and boom.

Add Classe when the item visible

Add class on scroll to viewport jquery code

HTML img tag to HTML SVG tag [WordPress]

Image to SVG for WordPress. Generate svg code from image file

Web Development Project in mind?

if you looking for a web developer for paid contribution to your project I am available for work.

Mukto
Mukto

Click the button below to chat with me.