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 *

ACF

Advanced Custom Fields code snippet

Advance custom field Link Field, Flexible content Field, Gallery and tricks code snippet

WordPress category or taxonomy list

WordPress custom taxonomy term list with function and loop. show taxonomy team on wp query loop

Create a new WordPress administrator via functions.php & FTP

Sometimes, you might need to create an administrator account in WordPress without being able to access the admin dashboard. This could be because you have lost access to your site’s admin panel or when troubleshooting a client’s website. In this tutorial, we will show you how to programmatically add a WordPress administrator account using the […]

Upload file in hosting server via CPanel corn job

File transfer with Cpanel Cron job. Transfer file super fast

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.