Skip to content

Instantly share code, notes, and snippets.

@isaumya
Created August 21, 2020 10:31
Show Gist options
  • Save isaumya/8e89c81e63e7a8a6801f902ef839e9a5 to your computer and use it in GitHub Desktop.
Save isaumya/8e89c81e63e7a8a6801f902ef839e9a5 to your computer and use it in GitHub Desktop.
Customizing WooCommerce Core Checkout Fields (Removing Address Line 2) and also change the placeholder text of Address Line 1
<?php
/**
* Remove Address Line 2 from WooCommerce Billing & Shipping Form
* Also add proper placeholder for Address line 1 to include the full address
* @author Acnam Infotech
*/
add_filter( 'woocommerce_checkout_fields', function( $fields ) {
if( is_array( $fields ) ) {
// Remove Address Line 2 from Billing & Shipping fields
unset( $fields['billing']['billing_address_2'] );
unset( $fields['shipping']['shipping_address_2'] );
// Change the placeholder for Address Line 1 for Billing & Shipping address section
$fields['billing']['billing_address_1']['placeholder'] = 'House no, street, apartment, suite, unit';
$fields['shipping']['shipping_address_1']['placeholder'] = 'House no, street, apartment, suite, unit';
}
return $fields;
} );
/**
* Updating the default WooCommerce Country Local values for changing placeholder texts properly
*/
add_filter('woocommerce_get_country_locale_default', function( $default_locales ) {
if( is_array( $default_locales ) ) {
foreach( $default_locales as $key => $value ) {
if( $key === 'address_1' ) {
$default_locales['address_1']['placeholder'] = 'House no, street, apartment, suite, unit';
}
}
}
return $default_locales;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment