skip to Main Content

Is it possible to display these following radio buttons before payment gateways in check-out page:

  • "Pay at property"
    Your card won’t be charged, we only need your card details to
    guarantee your booking.

  • "Pay now"
    We will handle payment. You will receive a full refund if you change your mind before 31 December 2020.

Customers must choose one of these 2 buttons so one of these 2 buttons is required.

Then to make it appears in order mail for admin and customers.

If you have the solution, it will help me a lot !

2

Answers


  1. 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>
    Login or Signup to reply.
  2. You can use woocommerce_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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search