Forum Replies Created

Viewing 11 replies - 1 through 11 (of 11 total)
  • Thread Starter patyg

    (@patyg)

    Also, how do I transform the country part in the register form to be a dropdown such as in the checkout page?

    I need this too ??

    Thread Starter patyg

    (@patyg)

    EDIT:
    after more research I now have this code:

    /**
     * Plugin Name: WooCommerce Registration Fields
     * Plugin URI: https://claudiosmweb.com/
     * Description: My Custom registration fields.
     * Version: 1.0
     * Author: Claudio Sanches
     * Author URI: https://claudiosmweb.com/
     * License: GPL2
     */
    /**
     * Add new register fields for WooCommerce registration.
     *
     * @return string Register fields HTML.
     */
    function wooc_extra_register_fields() {
        ?>
    
        <p class="form-row form-row-first">
        <label for="reg_billing_first_name"><?php _e( 'First name', 'woocommerce' ); ?> <span class="required">*</span></label>
        <input type="text" class="input-text" name="billing_first_name" id="reg_billing_first_name" value="<?php if ( ! empty( $_POST['billing_first_name'] ) ) esc_attr_e( $_POST['billing_first_name'] ); ?>" />
        </p>
    
        <p class="form-row form-row-last">
        <label for="reg_billing_last_name"><?php _e( 'Last name', 'woocommerce' ); ?> <span class="required">*</span></label>
        <input type="text" class="input-text" name="billing_last_name" id="reg_billing_last_name" value="<?php if ( ! empty( $_POST['billing_last_name'] ) ) esc_attr_e( $_POST['billing_last_name'] ); ?>" />
        </p>
    
        <p class="form-row form-row-last">
        <label for="reg_billing_company"><?php _e( 'Company', 'woocommerce' ); ?> <span class="required">*</span></label>
        <input type="text" class="input-text" name="billing_company" id="reg_billing_company" value="<?php if ( ! empty( $_POST['billing_company'] ) ) esc_attr_e( $_POST['billing_company'] ); ?>" />
        </p>
    
        <p class="form-row form-row-last">
        <label for="reg_billing_address_1"><?php _e( 'Job Title', 'woocommerce' ); ?> <span class="required">*</span></label>
        <input type="text" class="input-text" name="billing_address_1" id="reg_billing_address_1" value="<?php if ( ! empty( $_POST['billing_address_1'] ) ) esc_attr_e( $_POST['billing_address_1'] ); ?>" />
        </p>
    
        <p class="form-row form-row-last">
        <label for="reg_billing_address_2"><?php _e( 'Website', 'woocommerce' ); ?> <span class="required">*</span></label>
        <input type="text" class="input-text" name="billing_address_2" id="reg_billing_address_2" value="<?php if ( ! empty( $_POST['billing_address_2'] ) ) esc_attr_e( $_POST['billing_address_2'] ); ?>" />
        </p>
    
        <div class="clear"></div>
    
        <p class="form-row form-row-wide">
        <label for="reg_billing_phone"><?php _e( 'Phone', 'woocommerce' ); ?> <span class="required">*</span></label>
        <input type="text" class="input-text" name="billing_phone" id="reg_billing_phone" value="<?php if ( ! empty( $_POST['billing_phone'] ) ) esc_attr_e( $_POST['billing_phone'] ); ?>" />
        </p>
    
        <p class="form-row form-row-wide">
        <label for="reg_billing_city"><?php _e( 'City', 'woocommerce' ); ?> <span class="required">*</span></label>
        <input type="text" class="input-text" name="billing_city" id="reg_billing_city" value="<?php if ( ! empty( $_POST['billing_city'] ) ) esc_attr_e( $_POST['billing_city'] ); ?>" />
        </p>
    
        <p class="form-row form-row-wide">
        <label for="reg_billing_state"><?php _e( 'State', 'woocommerce' ); ?></label>
        <input type="text" class="input-text" name="billing_state" id="reg_billing_state" value="<?php if ( ! empty( $_POST['billing_state'] ) ) esc_attr_e( $_POST['billing_state'] ); ?>" />
        </p>
    
        <p class="form-row form-row-wide">
        <label for="reg_billing_country"><?php _e( 'Country', 'woocommerce' ); ?> <span class="required">*</span></label>
        <input type="text" class="input-text" name="billing_country" id="reg_billing_country" value="<?php if ( ! empty( $_POST['billing_country'] ) ) esc_attr_e( $_POST['billing_country'] ); ?>" />
        </p>
    
        <p class="form-row form-row-wide">
        <label for="reg_billing_postcode"><?php _e( 'How did you hear about Nomadous?', 'woocommerce' ); ?></label>
        <input type="text" class="input-text" name="billing_postcode" id="reg_billing_postcode" value="<?php if ( ! empty( $_POST['billing_postcode'] ) ) esc_attr_e( $_POST['billing_postcode'] ); ?>" />
        </p>
    
        <?php
    }
    
    add_action( 'woocommerce_register_form_start', 'wooc_extra_register_fields' );
    
    /**
     * Validate the extra register fields.
     *
     * @param  string $username          Current username.
     * @param  string $email             Current email.
     * @param  object $validation_errors WP_Error object.
     *
     * @return void
     */
    function wooc_validate_extra_register_fields( $username, $email, $validation_errors ) {
        if ( isset( $_POST['billing_first_name'] ) && empty( $_POST['billing_first_name'] ) ) {
            $validation_errors->add( 'billing_first_name_error', __( '<strong>Error</strong>: First name is required!', 'woocommerce' ) );
        }
    
        if ( isset( $_POST['billing_last_name'] ) && empty( $_POST['billing_last_name'] ) ) {
            $validation_errors->add( 'billing_last_name_error', __( '<strong>Error</strong>: Last name is required!.', 'woocommerce' ) );
        }
    
        if ( isset( $_POST['billing_company'] ) && empty( $_POST['billing_company'] ) ) {
            $validation_errors->add( 'billing_company_error', __( '<strong>Error</strong>: Company name is required!.', 'woocommerce' ) );
        }
    
        if ( isset( $_POST['billing_address_1'] ) && empty( $_POST['billing_address_1'] ) ) {
            $validation_errors->add( 'billing_address_1_error', __( '<strong>Error</strong>: Job title is required!.', 'woocommerce' ) );
        }
    
        if ( isset( $_POST['billing_address_2'] ) && empty( $_POST['billing_address_2'] ) ) {
            $validation_errors->add( 'billing_address_2_error', __( '<strong>Error</strong>: Website is required!.', 'woocommerce' ) );
        }
    
        if ( isset( $_POST['billing_phone'] ) && empty( $_POST['billing_phone'] ) ) {
            $validation_errors->add( 'billing_phone_error', __( '<strong>Error</strong>: Phone is required!.', 'woocommerce' ) );
        }
    
        if ( isset( $_POST['billing_city'] ) && empty( $_POST['billing_city'] ) ) {
            $validation_errors->add( 'billing_city_error', __( '<strong>Error</strong>: City is required!.', 'woocommerce' ) );
        }
    
        if ( isset( $_POST['billing_country'] ) && empty( $_POST['billing_country'] ) ) {
            $validation_errors->add( 'billing_country_error', __( '<strong>Error</strong>: Country is required!.', 'woocommerce' ) );
        }
    }
    
    add_action( 'woocommerce_register_post', 'wooc_validate_extra_register_fields', 10, 3 );
    
    /**
     * Save the extra register fields.
     *
     * @param  int  $customer_id Current customer ID.
     *
     * @return void
     */
    function wooc_save_extra_register_fields( $customer_id ) {
        if ( isset( $_POST['billing_first_name'] ) ) {
            // WordPress default first name field.
            update_user_meta( $customer_id, 'first_name', sanitize_text_field( $_POST['billing_first_name'] ) );
    
            // WooCommerce billing first name.
            update_user_meta( $customer_id, 'billing_first_name', sanitize_text_field( $_POST['billing_first_name'] ) );
        }
    
        if ( isset( $_POST['billing_last_name'] ) ) {
            // WordPress default last name field.
            update_user_meta( $customer_id, 'last_name', sanitize_text_field( $_POST['billing_last_name'] ) );
    
            // WooCommerce billing last name.
            update_user_meta( $customer_id, 'billing_last_name', sanitize_text_field( $_POST['billing_last_name'] ) );
        }
    
        if ( isset( $_POST['billing_company'] ) ) {
            // WooCommerce company
            update_user_meta( $customer_id, 'billing_company', sanitize_text_field( $_POST['billing_company'] ) );
        }
    
        if ( isset( $_POST['billing_address_1'] ) ) {
            // WooCommerce billing address 1
            update_user_meta( $customer_id, 'billing_address_1', sanitize_text_field( $_POST['billing_address_1'] ) );
        }
    
        if ( isset( $_POST['billing_address_2'] ) ) {
            // WooCommerce billing address 2
            update_user_meta( $customer_id, 'billing_address_2', sanitize_text_field( $_POST['billing_address_2'] ) );
        }
    
        if ( isset( $_POST['billing_phone'] ) ) {
            // WooCommerce billing phone
            update_user_meta( $customer_id, 'billing_phone', sanitize_text_field( $_POST['billing_phone'] ) );
        }
    
        if ( isset( $_POST['billing_city'] ) ) {
            // WooCommerce billing city
            update_user_meta( $customer_id, 'billing_city', sanitize_text_field( $_POST['billing_city'] ) );
        }
    
        if ( isset( $_POST['billing_state'] ) ) {
            // WooCommerce billing state
            update_user_meta( $customer_id, 'billing_state', sanitize_text_field( $_POST['billing_state'] ) );
        }
    
        if ( isset( $_POST['billing_country'] ) ) {
            // WooCommerce billing country
            update_user_meta( $customer_id, 'billing_country', sanitize_text_field( $_POST['billing_country'] ) );
        }
    
        if ( isset( $_POST['billing_postcode'] ) ) {
            // WooCommerce billing postcode
            update_user_meta( $customer_id, 'billing_postcode', sanitize_text_field( $_POST['billing_postcode'] ) );
        }
    }
    
    add_action( 'woocommerce_created_customer', 'wooc_save_extra_register_fields' );

    It now works on showing the fields in the registration for, but it is not adding it to checkout page. Help please?

    Both cart and checkout are working for me too once I added a product to the cart ??

    Thread Starter patyg

    (@patyg)

    Just did, thank you James!

    Thread Starter patyg

    (@patyg)

    Thank you Mayo_Joelle! Would it also work for registered users who are not admins?

    Thread Starter patyg

    (@patyg)

    Any help or direction please?

    Forum: Fixing WordPress
    In reply to: Slow website
    Thread Starter patyg

    (@patyg)

    Issue was solved by changing host.

    Thank you for the support!

    Forum: Fixing WordPress
    In reply to: Slow website
    Thread Starter patyg

    (@patyg)

    update:
    i was thinking maybe the problem was in the host, but the resources don’t seem to be overused, see below:
    https://snag.gy/1WhfS.jpg
    (hosted with Arvixe)

    Also, this happened after the website had a day with unusual high traffic.

    Now sure if it helps at all, hope it does!

    Forum: Fixing WordPress
    In reply to: Slow website
    Thread Starter patyg

    (@patyg)

    Thank you for your replies! I tried to login to dashboard to try to install p3 and disable google fonts, but it also doesn’t load the dashboard! Is there a way to try and fix this directly in the files?
    If so, how can I do it?

    Also I can’t test the website in the links you gave me:
    https://gtmetrix.com/leverage-browser-caching.html
    https://www.webpagetest.org/
    https://tools.pingdom.com
    https://developers.google.com/speed/pagespeed/insights/

    because it says it times out before the site loads ??

    Sorry for all the questions, but I really need help from someone more experienced dealing with this, it’s destroying my site ??

    Thank you again!

    Forum: Fixing WordPress
    In reply to: Slow website
    Thread Starter patyg

    (@patyg)

    Thank you for the links Tara.

    I applied it but it doesn’t seem to have fixed it. Do you have any other ideas about how to fix this?

    Again, thank you!

Viewing 11 replies - 1 through 11 (of 11 total)