Created
February 20, 2017 17:10
-
-
Save pablo-sg-pacheco/51ec035cd205e1999c9b70b48ee932c7 to your computer and use it in GitHub Desktop.
Positions a custom booster field in any order on checkout
This file contains hidden or 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 | |
add_filter( 'woocommerce_checkout_fields', function ( $fields ) { | |
$offset = 2; //Change this by the field position you want to add (remembering it starts from zero) | |
$custom_field_id = 'billing_wcj_checkout_field_1'; //Your custom field id | |
$oldArray = $fields['billing']; | |
$custom_field = array( $custom_field_id => $oldArray[ $custom_field_id ] ); | |
$newArray = array_slice( $oldArray, 0, $offset, true ) + $custom_field + array_slice( $oldArray, $offset, null, true ); | |
$fields['billing'] = $newArray; | |
return $fields; | |
}, PHP_INT_MAX ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@algoritmika
@anbinder