You can usewoocommerce_review_order_before_payment
action hook to display radio buttons before payment section in WooCommerce checkout page as follow:
// Display a Custom radio buttons input fields before checkout available payment gateways section
add_action( 'woocommerce_review_order_before_payment','checkout_customer_type_radio_buttons' );
function checkout_customer_type_radio_buttons() {
echo '<div id="custom-radio-buttons">';
echo '<h3>' . __("Your section sub-title", "woocommerce") . '</h3>';
// Here below set your field Id (or field key)
$field_id = '_custom_key';
woocommerce_form_field( $field_id, array(
'type' => 'radio',
'class' => array( 'some-class' ),
'options' => array(
'First Option' => __('First Option', 'woocommerce'),
'Second Option' => __('Second Option', 'woocommerce'),
),
'default' => 'First Option',
'required' => true,
), WC()->checkout->get_value( $field_id ) );
echo '</div>';
}
Code goes in functions.php file of your active child theme (or active theme). Tested and works.
Addition - For a better display you can use instead the following:
// Display a Custom radio buttons input fields before checkout available payment gateways section
add_action( 'woocommerce_review_order_before_payment','checkout_customer_type_radio_buttons' );
function checkout_customer_type_radio_buttons() {
## YOUR RADIO BUTTONS SETTINGS BELOW:
$field_id = '_custom_key'; // HERE below set your field Id (or field key)
$options = array( // HERE below set your radio button options in the array:
__('First Option', 'woocommerce'),
__('Second Option', 'woocommerce'),
__('Third Option', 'woocommerce'),
);
$default = reset($options); // HERE set default checked option (The first one is set in here)
echo '<div id="custom-radio-buttons">';
echo '<h3>' . __("Your section sub-title (optional)", "woocommerce") . '</h3>';
echo '<p class="form-row some-class validate-required" id="'.$field_id.'_field">
<span class="woocommerce-input-wrapper">';
$value = WC()->checkout->get_value( $field_id );
$value = empty($value) ? $default : $value;
// Loop through defined options array
foreach( $options as $option ) {
$checked = $option === $value ? ' checked="checked"' : '';
echo '<label for="'.$field_id.'_'.$option.'"><input type="radio" class="input-radio " name="'.$field_id.'" id="'.$field_id.'_'.$option.'" value="'.$option.'"'.$checked.'> ' . $option . '</label>';
}
echo '</span></p></div>';
}
Related thread: Show/Hide WooCommerce Shipping Rates Based on Radio Buttons
I don't know if it's work
Using form in HTML that has 2 radials and group them in the same name attribute for required. That makes the customer have to choose one of them. And then POST the value from value attribute, so you can use the value for the next process you want
<form action="/page.php" method="POST">
<label for="payAtProperty">
<input type="radio" id="payAtProperty" name="payMethod" value="method-1" required>
"Pay at property" <br> "Your card won't be charged, we only need your card details to guarantee your booking."
</label><br>
<label for="payNow">
<input type="radio" id="payNow" name="payMethod" value="method-2">
"Pay now" <br> We will handle payment. You will receive a full refund if you change your mind before 31 December 2020.
</label><br><br>
<input type="submit" value="Submit">
</form>
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
HTML (English "hyper text markup language" - hypertext markup language) is a special markup language that is used to create sites on the Internet.
Browsers understand html perfectly and can interpret it in an understandable way. In general, any page on the site is html-code, which the browser translates into a user-friendly form. By the way, the code of any page is available to everyone.
https://www.w3.org/html/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.