Skip to content

Instantly share code, notes, and snippets.

@pablo-sg-pacheco
Created February 20, 2017 17:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pablo-sg-pacheco/51ec035cd205e1999c9b70b48ee932c7 to your computer and use it in GitHub Desktop.
Save pablo-sg-pacheco/51ec035cd205e1999c9b70b48ee932c7 to your computer and use it in GitHub Desktop.
Positions a custom booster field in any order on checkout
<?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 );
@pablo-sg-pacheco
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment