Last active
February 12, 2019 22:07
-
-
Save damiencarbery/2cc91644a375f6b8f0a0d99be8ee5124 to your computer and use it in GitHub Desktop.
Change WooCommerce checkout field order: https://www.damiencarbery.com/2019/02/change-woocommerce-checkout-field-order/ Changing the WooCommerce checkout fields display order is much simpler and more robust with the use of a 'priority' element in the field definition.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Add House Number field (WooCommerce) | |
Plugin URI: https://businessbloomer.com/woocommerce-add-house-number-field-checkout/ | |
Description: Add a House Number field to WooCommerce checkout. | |
Author: Rodolfo Melogli & Damien Carbery | |
Version: 0.2 | |
*/ | |
add_filter( 'woocommerce_checkout_fields' , 'bbloomer_add_field_and_reorder_fields' ); | |
function bbloomer_add_field_and_reorder_fields( $fields ) { | |
// Add New Fields | |
$fields['billing']['billing_houseno'] = array( | |
'label' => 'House Number', | |
'placeholder' =>'House Number', | |
'required' => true, | |
'class' => array('form-row-last'), | |
'clear' => true, | |
'priority' => $fields['billing']['billing_address_1']['priority'] + 5, | |
); | |
$fields['shipping']['shipping_houseno'] = array( | |
'label' => 'House Number', | |
'placeholder' => 'House Number', | |
'required' => true, | |
'class' => array('form-row-last'), | |
'clear' => true, | |
'priority' => $fields['shipping']['shipping_address_1']['priority'] + 5, | |
); | |
// Remove Address_2 Fields | |
unset($fields['billing']['billing_address_2']); | |
unset($fields['shipping']['shipping_address_2']); | |
// Make Address_1 Fields Half Width | |
$fields['billing']['billing_address_1']['class'] = array('form-row-first'); | |
$fields['shipping']['shipping_address_1']['class'] = array('form-row-first'); | |
return $fields; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment