• Resolved Debora1976

    (@debora1976)


    Hello,

    A lot of customers forget to add their housenumber to the address field, so I use this function to check this.
    But this function doens’t work on the my account page edit address.

    Who knows the solution?
    add_action( ‘woocommerce_after_checkout_validation’, ‘validate_checkout’, 10, 2);
    function validate_checkout( $data, $errors ){
    if ( ! preg_match(‘/[0-9]/’, $data[ ‘billing_address_1’ ] ) ){
    $errors->add( ‘address’, ‘Er is geen huisnummer ingevuld.’ );
    }
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support ckadenge (woo-hc)

    (@ckadenge)

    Hi @debora1976,

    Thank you for reaching out.

    Helping out with custom coding of this nature is outside the scope of support that we can help out with here. Although, I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    You can visit the WooCommerce Facebook group or the #developers channel of the WooCommerce Community Slack for faster assistance.

    We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Thread Starter Debora1976

    (@debora1976)

    Hi,

    I figured it out myself, so you can close this item.





    add_filter( ‘woocommerce_process_myaccount_field_billing_address_1’ , ‘validate_edit_address’ );
    function validate_edit_address() {

            $post_value = $_POST['billing_address_1'];
    
    // If there is no number in this field value, stops the checkout process
    // and displays an error message.
    if ( $post_value && ! preg_match( '/[0-9]+/', $post_value ) ) {
    
        wc_add_notice( __( 'Vul je voornaam, achternaam, straat én huisnummer, postcode, woonplaats en e-mailadres in en selecteer een land.' ), 'error' );
    }
    return $post_value ; 

    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.