Skip to content

Instantly share code, notes, and snippets.

@woogists
Created March 9, 2018 16:28
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 woogists/7327d81dde3370b9c87e13848b70d094 to your computer and use it in GitHub Desktop.
Save woogists/7327d81dde3370b9c87e13848b70d094 to your computer and use it in GitHub Desktop.
[Checkout Field Editor] Setting a default value for a radio button field
function custom_override_checkout_fields ( $fields ) {
$fields['billing']['test_radio']['default'] = 'one';
return $fields;
} // End custom_override_checkout_fields()
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
@gsibert
Copy link

gsibert commented Jul 19, 2022

Same for me, can't get it to work with Additional Fields.

@gsibert
Copy link

gsibert commented Jul 19, 2022

For anyone else that finds themselves here with the same issue. I found that the WooCommerce Checkout Field Editor plugin set a priority of 1000 for their add_filter. So in order to customize things in additional (which is actually order) change the snippet to this which worked for me:

function custom_override_checkout_fields ( $fields ) {
	$fields['order']['email_optin']['default'] = 'Yes';
	return $fields;
} // End custom_override_checkout_fields()

add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' , 1100 );

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