
Messy order of gift fields on the checkout page could be caused by a priority value set incorrectly for these fields. Maybe the same number is set for all 4 fields. While it should be a sequence.
For example, we want to put all LearnDash Gift fields before billing_first_name, which has priority of 10 by default.
Then we need to assign priorities of 6,7,8,9 to all 4 gift fields accordingly. Not priority 9 to all four fields.
Here’s the code you need to paste into functions.php of your theme to move LearnDash Gift plugin fields up above the billing_first_name field:
These are some extra notes below this code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | function bf_ldg_checkout_fields_priority( $fields ) { if( !empty( $fields['billing'] ) ) { if( !empty( $fields['billing']['gift_purchase'] ) ) { $fields['billing']['gift_purchase']['priority'] = '6'; } if( !empty( $fields['billing']['gift_name'] ) ) { $fields['billing']['gift_name']['priority'] = '7'; } if( !empty( $fields['billing']['gift_email'] ) ) { $fields['billing']['gift_email']['priority'] = '8'; } if( !empty( $fields['billing']['gift_note'] ) ) { $fields['billing']['gift_note']['priority'] = '9'; } } return $fields; } add_filter( 'woocommerce_checkout_fields', 'bf_ldg_checkout_fields_priority', 11, 1 ); |
P.S. If you want to move your LearnDash Gift fields to any other place than the very top of checkout form, here’s how you can achieve that.
On WooCommerce checkout page each field has a default priority value. And in the code above, I use values of 6, 7, 8, 9 for LearnDash Gift fields. This positions Gift fields before billing_first_name field, which has value of 10.
Following the same path and the code above, you could move LearnDash Gift fields to any position on WooCommerce checkout form.
Here is the summary of default priority values for all checkout fields:
Group | Name | Priority |
---|---|---|
billing | billing_first_name | 10 |
– | billing_last_name | 20 |
– | billing_company | 30 |
– | billing_country | 40 |
– | billing_address_1 | 50 |
– | billing_address_2 | 60 |
– | billing_city | 70 |
– | billing_state | 80 |
– | billing_postcode | 90 |
– | billing_phone | 100 |
– | billing_email | 110 |
shipping | shipping_first_name | 10 |
– | shipping_last_name | 20 |
– | shipping_company | 30 |
– | shipping_country | 40 |
– | shipping_address_1 | 50 |
– | shipping_address_2 | 60 |
– | shipping_city | 70 |
– | shipping_state | 80 |
– | shipping_postcode | 90 |
account | account_password | – |
order | order_comments | – |