• Resolved Ashley

    (@nosegraze)


    I have read this FAQ: Custom field not validated when clicking the PayPal button.

    As a test, I have added this exact code to my site:

    /**
    * 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 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’ );
    }
    });

    Here’s how checkout looks:

    When I click the yellow “PayPal” button, I expect to need to click the checkbox. But instead, the PayPal window pops up and I’m able to proceed all the way through to payment.

    My understanding of reading that doc was that the required field should be validated first. That does not seem to be happening. Am I misunderstanding? Or is this not working correctly?

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Krystian from Syde

    (@inpsydekrystian)

    Hello @nosegraze

    I suggest removing the Classic Checkout block from your checkout page and then reinserting it using the shortcode [woocommerce_checkout].

    We have found that the functionality of the Classic Checkout block can be bugged when it’s converted to Classic Checkout via the WordPress editor. Reinserting the block should restore its functionality and allow the custom checkbox validation to work as intended.

    Please try this solution and let us know if the issue persists.

    Kind Regards,

    Krystian

    Thread Starter Ashley

    (@nosegraze)

    @inpsydekrystian That worked! Thanks so much for your help. ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom field not validated with PayPal button’ is closed to new replies.