• Resolved jstneti

    (@jstneti)


    I need to add a compulsory checkbox to the checkout field. I added the checkbox with the woocommerce_review_order_before_submit action and it works for COD but not for PayPal Payments. If the checkbox is UNchecked, it still opens up the PayPal window. This should not happen. Only when all required fields are populated and validated, it should open the PayPal window.

    I’m using the latest version of the plugin. Is this a known bug or should I be using aother hook to add the checkbox or perhaps an additional checkbox for it to work with PP Payments?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter jstneti

    (@jstneti)

    To add more data, I use this snippet: https://www.businessbloomer.com/woocommerce-additional-acceptance-checkbox-checkout/

    And when clicking the “pay with paypal” button, it only checks for the billing required fields but proceeds with the new checkbox unchecked. After filling all the PayPal info and finishing the process it takes me back to the checkout page and displays the error message – as it should have done before opening the PP window. The order is never placed, so that part works fine.

    Plugin Support Krystian

    (@inpsydekrystian)

    Hello @jstneti

    We recently updated our documentation to address the problem you are facing. You can find more detailed information about this issue and its solution in our documentation here: PayPal Payments Plugin Documentation.

    It seems like the code snippet you are using should generally work with most payment plugins. However, in PayPal Payments we recommend using the woocommerce_after_checkout_validation hook instead of the woocommerce_checkout_process. This should ensure that your custom checkbox is properly validated before proceeding with the PayPal payment process. Example code is below:

    /**
     * Add a checkbox field to the checkout
     **/
    add_action( 'woocommerce_review_order_before_submit', function() {
        woocommerce_form_field( 'custom_checkbox', array(
            'type'          => 'checkbox',
            'required'      => true,
            'label'         => 'This checkbox must be checked to proceed with the payment.',
        )); 
    }, 9 );
    
    /**
     * Validate the checkbox field on the checkout when clicking "Place order" button
     **/
    add_action( 'woocommerce_after_checkout_validation', function() {
        if ( ! isset( $_POST['custom_checkbox'] ) ) {
            wc_add_notice( __( 'Please acknowledge the required checkbox.' ), 'error' );
        }
    });
    

    If you require further assistance or have any more questions, please feel free to contact us. We are here to help!

    Kind Regards,

    Krystian

    Thread Starter jstneti

    (@jstneti)

    Yes, that works fine. Thank you very much for the quick response.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Required field not working with plugin’ is closed to new replies.