• Resolved n4gash

    (@n4gash)


    Hi,

    I’m developing a e-commerce using WordPress + Woocommerce. For the payments we are using Stripe and we have configured it successfully. However, we have a question regarding the checkout form. For payments Woocommerce has a form for get personal and shipment information. Stripe’s plugin introduce his own form for credit card’s fields.

    We want to add a new field to the form (checkbox to accept privacy policy), and we want to be checked and validated by WordPress system. It works, but for any reason, the form first validate the woocommerce’s fields, then Stripe fields, and finally my new custom field.

    I have added this code in functions.php

    /* PRIVACY POLICY -> ADD CHECKBOX  */ 
    add_action( 'woocommerce_review_order_before_submit', 'add_privacy_checkbox', 9 );
    	function add_privacy_checkbox() {
    		woocommerce_form_field( 'privacy_policy', array(
    		'type' => 'checkbox',
    		'class' => array('form-row privacy'),
    		'label_class' => array('woocommerce-form__label woocommerce-form__label-for-checkbox checkbox'),
    		'input_class' => array('woocommerce-form__input woocommerce-form__input-checkbox input-checkbox'),
    		'required' => true,
    		'label' => 'He leído y aceptado la <a href="www.myweb.com/privacy.php" target="blank">pol&iacute;tica de privacidad</a>',
    		));
    	}
    
    add_action('woocommerce_checkout_process', 'privacy_checkbox_error_message');
    
        function privacy_checkbox_error_message() {
    
            if ( ! (int) isset( $_POST['privacy_policy'] ) ) 
              wc_add_notice( __( 'Debes aceptar nuestra pol&iacute;tica de privacidad.' ), 'error' );
    }

    As far I know, we can modify the order of validation using hooks. I think that “woocommerce_checkout_process” should be executed before Stripe is fired, but not…. when I click on CHECKOUT, the system validates all woocommerce fields (including accept terms and conditions), but not my new custom field, before it, the system validates the Stripe’s fields.

    Do you know how can we change the order / priority of validation of fields? we want to leave the Stripe’s validation at the end.

    Thanks in advance for your time
    Cheers

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support dougaitken

    (@dougaitken)

    Automattic Happiness Engineer

    Hey @n4gash

    It looks like your query has gone unanswered due to the custom nature of the request and no one has been able to help out.

    > We want to add a new field to the form (checkbox to accept privacy policy), and we want to be checked and validated by WordPress system. It works, but for any reason, the form first validate the woocommerce’s fields, then Stripe fields, and finally my new custom field.

    This is a fairly complex development topic and isn’t specific to Stripe, but rather your whole site.

    I’m going to leave it open for a week more to see if anyone is able to chime in to help you out.??I can also recommend the following places for more development-oriented questions:??
    WooCommerce Slack Community: https://woocommerce.com/community-slack/
    Advanced WooCommerce group on Facebook: https://www.facebook.com/groups/advanced.woocommerce/

    Thanks,

    Plugin Support dougaitken

    (@dougaitken)

    Automattic Happiness Engineer

    Hi @n4gash

    I hope you’ve found a solution to what you’re looking for.

    We haven’t heard back from you in a while, so I’m going to mark this as resolved – if you have any further questions, you can start a new thread.

    As a note – People will still be able to respond to this post even after it is resolved.

    Thanks,

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Change Stripe’s validation fields at the end’ is closed to new replies.