• Resolved brock40

    (@brock40)


    How can I create additional radio buttons next to the terms and conditions at check out page. I’d like to do this without a plugin, I believe it can be done by editing the functions.php or using code snippets. Does anyone have the code?

    It should look like the link here: radio buttons image at check out page

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi @brock40!

    Thank you for reaching out.

    There is no option to add extra radio buttons at the checkout page in WooCommerce core; you would need a plugin or custom coding to achieve it.

    Searching, I found a custom code that gets close to what you want to achieve; you can take a look at it for pointers:

    https://gist.github.com/mikeott/24618f6b770ae34e00580522d804125c

    It will add radio buttons to your checkout page; you can edit it to fit your needs. You can use a plugin like Code Snippets to add this snippet without having to edit your PHP code.

    Also, you could use one of these extensions to add radio buttons to your checkout page:

    Checkout Field Editor
    Custom Fields for WooCommerce
    Checkout Fields Manager
    https://www.ads-software.com/plugins/search/checkout+field/

    Anyway, I am leaving this thread open for a while to see if anyone can chime in to help you out.

    For additional assistance on this topic, we recommend getting in touch with one of the customization experts listed on the WooCommerce Customizations Page.

    I hope this helps!

    Thread Starter brock40

    (@brock40)

    Cloudways use to have a write up on their blog to do this, but I couldn’t find it. I use to have it on one of my websites and would like to add it to my new one.

    You’re correct, I did use Code snippets. But, finding the code to have it done is a difficult Google search. Maybe, Cloudways deleted their blog article.

    Thread Starter brock40

    (@brock40)

    I tried adding this to code snippets and it didn’t work. I’m not a coder so I’m sure something isn’t right.

    <?php
    /*
    Add custom radio buttons to checkout.
    Requires WooCommerce v3+

    Add your radio buttons.
    Remove the ‘required’ attribute if these are to be optional.
    */
    add_action( ‘woocommerce_review_order_before_payment’, ‘display_extra_fields_after_billing_address’ , 10, 1 );
    function display_extra_fields_after_billing_address () { ?>
    <p><input type=”radio” name=”delivery_option” value=”I certify that I am over 18 years of age.” required /> I certify that I am over 18 years of age.</p>
    <p><input type=”radio” name=”delivery_option” value=”I certify that I/My organization is properly trained and qualified to handle the items being purchased.” /> I certify that I/My organization is properly trained and qualified to handle the items being purchased.</p>
    <?php
    }`

    Thread Starter brock40

    (@brock40)

    I figured it out if anyone else searches for the answer, no plugin required other than code snippets. Or just editing functions.php

    Here is the code:

    add_action('woocommerce_checkout_before_terms_and_conditions', 'checkout_additional_checkboxes');
    function checkout_additional_checkboxes( ){
        $checkbox1_text = __( "My first checkbox text", "woocommerce" );
        $checkbox2_text = __( "My Second checkbox text", "woocommerce" );
        ?>
        <p class="form-row custom-checkboxes">
            <label class="woocommerce-form__label checkbox custom-one">
                <input type="checkbox" class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox" name="custom_one" > <span><?php echo  $checkbox1_text; ?></span> <span class="required">*</span>
            </label>
            <label class="woocommerce-form__label checkbox custom-two">
                <input type="checkbox" class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox" name="custom_two" > <span><?php echo  $checkbox2_text; ?></span> <span class="required">*</span>
            </label>
        </p>
        <?php
    }

    Second part of code makes it mandatory to check the boxes.

    add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process');function my_custom_checkout_field_process() {
        // Check if set, if its not set add an error.
        if ( ! $_POST['custom_one'] )
            wc_add_notice( __( 'You must accept "My first checkbox".' ), 'error' );
        if ( ! $_POST['custom_two'] )
            wc_add_notice( __( 'You must accept "My second checkbox".' ), 'error' );
    }

    Hello,

    I tried adding this to code snippets and it didn’t work.

    I was checking that as well, it is working on my testing site (after replacing ' and ") that is using WooCommerce, code snippets (this is to avoid editing directly the functions.php file), and Storefront


    Link to image: https://snipboard.io/LAPuRY.jpg

    I figured it out if anyone else searches for the answer

    Thanks so much for sharing your solution ??

    Cheers.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Create additional radio buttons next to terms and conditions’ is closed to new replies.