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
Yes, that works fine. Thank you very much for the quick response.
