Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[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