The following code generates 2 radio buttons. make each button display on a new line. woocommerce_form_field( $field_id, array( ‘type’ => $field_type, ‘label’ => ”, ‘class’ => array(‘form-row-wide ‘ . $field_id . ‘-‘ . $field_type ), ‘options’ => $field_options, ‘default’ => $field_default, ‘required’ => true, ), empty($value) ? WC()->checkout->get_value(‘_’.$field_id) : $value );

WordPress AI Code Robot

Create WordPress code snippets for free without a developer!

{Name (First):7.3} requested the  following code from my WordPress AI Code Generator.

The following code generates 2 radio buttons. make each button display on a new line.

woocommerce_form_field( $field_id, array(
'type' => $field_type,
'label' => '',
'class' => array('form-row-wide ' . $field_id . '-' . $field_type ),
'options' => $field_options,
'default' => $field_default,
'required' => true,
), empty($value) ? WC()->checkout->get_value('_'.$field_id) : $value );

The robot generated the following code:

Your WordPress/WooCommerce code snippet will look like this:

“`PHP
function nm_create_radio_buttons($field_id, $field_type, $field_options, $field_default, $value){
woocommerce_form_field( $field_id, array(
'type' => $field_type,
'label' => '',
'class' => array('form-row-wide ', $field_id . '-' . $field_type, 'nm_radio_buttons_new_line'),
'options' => $field_options,
'default' => $field_default,
'required' => true,
), empty($value) ? WC()->checkout->get_value('_'.$field_id) : $value );
}
add_action('woocommerce_after_checkout_form', 'nm_create_radio_buttons');

function nm_add_new_line_for_radio_buttons(){
?>
<style>
.nm_radio_buttons_new_line [type="radio"] {
display: block;
}
</style>
<?php
}
add_action( 'wp_head', 'nm_add_new_line_for_radio_buttons' );
“`

Explanation:

The `nm_create_radio_buttons` function generates 2 or more radio buttons based on the input parameters.

We utilize the `woocommerce_after_checkout_form` action to call our `nm_create_radio_buttons` function. Note that you will need to manually provide the necessary parameters for it to work.

The `nm_add_new_line_for_radio_buttons` function is used to add custom CSS to our WordPress theme using the `wp_head` action. The custom CSS targets radio buttons in the specific class we used in our form field and changes their display attribute to 'block'. This will separate each radio button onto a new line.

Please replace the method for providing parameters in `nm_create_radio_buttons` as per your requirement.

More
CODE SNIPPETS