• Resolved renecamello

    (@renecamello)


    So i was looking for a way to add a custom field in my woocommmerce registration form, i found this documentation and i followed it.

    After i implemented this my site started doing weird thing, its not loading the media page in my backend after i saved this code and i cannot publish my page anymore as it gives the error “Looks like something’s gone wrong. Wait a couple seconds, and then try again.” on this link are screenshots of the errors.

    I made some changes in the code of the documentation the following code is in my functions.php file:

    <!-- add a extra field for phone number to sign up form -->
    <?php function woocom_extra_register_fields() {?>
    
    <p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide">
        <label for="reg_billing_phone"><?php _e( 'Phone', 'woocommerce' ); ?><span class="required">*</span></label>
        <input type="text" class="woocommerce-Input woocommerce-Input--text input-text" name="billing_phone" id="reg_billing_phone" value="<?php if ( ! empty( $_POST['billing_phone'] ) ) esc_attr_e( $_POST['billing_phone'] ); ?>" /></p>
    <?php
    
    }
    
    add_action( 'woocommerce_register_form_start', 'woocom_extra_register_fields' );
    
    // add validation to the field above
    
    function woocom_validate_extra_register_fields( $username, $email, $validation_errors )
    
    {
    
    if (isset($_POST['billing_phone']) && empty($_POST['billing_phone']) ) {
    
    $validation_errors->add('billing_phone_error', __('Telefoon is verplicht', 'woocommerce'));
    
    }
    
    return $validation_errors;
    
    }
    
    add_action('woocommerce_register_post', 'woocom_validate_extra_register_fields', 10, 3);
    
    // add the added data to the database
    
    function woocom_save_extra_register_fields($customer_id) {
    
     
    
        if (isset($_POST['billing_phone'])) {
        
        update_user_meta($customer_id, 'billing_phone', sanitize_text_field($_POST['billing_phone']));
        
        }
    
        }
        
        add_action('woocommerce_created_customer', 'woocom_save_extra_register_fields');

    Does someone know how to fix my problem?

    Kind regards,
    René

    • This topic was modified 2 years, 7 months ago by Jan Dembowski.
    • This topic was modified 2 years, 7 months ago by James Huff.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Media page not loading after i added a custom woocommerce field in registration’ is closed to new replies.