Search code examples
phpwordpresswoocommercegetgravityforms

WooCommerce: pre populate registration fields with parameters from URL


I'm using a small form (Gravity Forms) on my site which asks for first name, last name and e-mail. After sending the form it redirects to the WooCommerce registration page and adds some parameters to the URL.

The URL looks like this: https://example.com/?first_name=First&last_name=Name&email=info%40example.com

Now I've changed the WooCommerce Template form-login.php with this code (for the e-mail field):

<?php $first_name = $_GET['first_name']; ?>
<?php $last_name = $_GET['last_name']; ?>
<?php $email = $_GET['email']; ?>

<div class="form-group">
    <label for="reg_email"><?php _e( 'Email address', 'woocommerce' ); ?> <span class="required">*</span></label>
    <input type="email" class="form-control" name="email" id="reg_email" value="<?php if ( ! empty( $_POST['email'] ) ) echo esc_attr( $_POST['email'] ); ?><?php if ( !empty($email) ) : echo $email; endif; ?>" placeholder="[email protected]" />
</div>

It works for this field because I can change it. (Is it ok how it's done?)

The problem is, I can't see the fields for first and last name in the template. Therefore I don't know how to change them or add the parameter.

Is there any trick?


Solution

  • I could solve the problem... My mistake!

    I've added the fields for first and last name like in this tutorial: https://businessbloomer.com/woocommerce-add-first-last-name-account-register-form/

    Now I could add the paramaters like above.