tier-pricing-table
/
src
/
Addons
/
NonLoggedInUsers
/
Wholesale
/
views
/
frontend
/
registration-form.php
registration-form.php in Tiered Pricing Table for WooCommerce 8.0.2, at src/Addons/NonLoggedInUsers/Wholesale/views/frontend/registration-form.php
| 1 | <?php |
| 2 | /** |
| 3 | * Wholesale registration form. |
| 4 | * |
| 5 | * Override it by copying this file to yourtheme/tiered-pricing-table/registration-form.php. |
| 6 | * |
| 7 | * @var WP_User|null $user the logged-in customer, or null for a guest |
| 8 | * @var array $fields the form's fields: [ key, label, type, required, options ] each |
| 9 | * @var bool $needsPassword whether to ask for a password |
| 10 | * @var int $termsPageId page id of the terms, 0 for none |
| 11 | * @var WP_Error|null $errors |
| 12 | * @var array $values |
| 13 | * @var string $title |
| 14 | * @var string $intro |
| 15 | * @var string $submitText |
| 16 | * @var string $recaptchaKey reCAPTCHA v3 site key, empty when off |
| 17 | * @var string $loginUrl |
| 18 | * @var \TierPricingTable\Addons\NonLoggedInUsers\Wholesale\Frontend\RegistrationForm $form |
| 19 | */ |
| 20 | |
| 21 | use TierPricingTable\Addons\NonLoggedInUsers\Wholesale\Frontend\RegistrationForm; |
| 22 | |
| 23 | if ( ! defined( 'WPINC' ) ) { |
| 24 | die; |
| 25 | } |
| 26 | |
| 27 | $hasErrors = $errors instanceof WP_Error && $errors->has_errors(); |
| 28 | $formId = 'tpt-wholesale-form'; |
| 29 | ?> |
| 30 | <div class="tpt-wholesale"> |
| 31 | <?php if ( $title ) : ?> |
| 32 | <h2 class="tpt-wholesale__title"><?php echo esc_html( $title ); ?></h2> |
| 33 | <?php endif; ?> |
| 34 | |
| 35 | <?php if ( $intro ) : ?> |
| 36 | <p class="tpt-wholesale__intro"><?php echo wp_kses_post( $intro ); ?></p> |
| 37 | <?php endif; ?> |
| 38 | |
| 39 | <?php if ( $hasErrors ) : ?> |
| 40 | <ul class="woocommerce-error tpt-wholesale__errors" role="alert"> |
| 41 | <?php foreach ( $errors->get_error_messages() as $message ) : ?> |
| 42 | <li><?php echo esc_html( $message ); ?></li> |
| 43 | <?php endforeach; ?> |
| 44 | </ul> |
| 45 | <?php endif; ?> |
| 46 | |
| 47 | <form method="post" class="tpt-wholesale__form woocommerce-form" id="<?php echo esc_attr( $formId ); ?>" novalidate> |
| 48 | <?php wp_nonce_field( RegistrationForm::NONCE, RegistrationForm::NONCE ); ?> |
| 49 | <input type="hidden" name="tpt_wholesale_action" value="register"> |
| 50 | |
| 51 | <?php // honeypot: hidden from people, filled by bots ?> |
| 52 | <div class="tpt-wholesale__hp" aria-hidden="true"> |
| 53 | <label for="tpt_wholesale_website_url">Website URL</label> |
| 54 | <input type="text" name="tpt_wholesale_website_url" id="tpt_wholesale_website_url" value="" tabindex="-1" autocomplete="off"> |
| 55 | </div> |
| 56 | |
| 57 | <?php if ( ! $user ) : ?> |
| 58 | <div class="tpt-wholesale__row tpt-wholesale__row--half"> |
| 59 | <p class="form-row <?php echo $form->error( 'first_name' ) ? 'woocommerce-invalid' : ''; ?>"> |
| 60 | <label for="tpt_wholesale_first_name"><?php esc_html_e( 'First name', 'tier-pricing-table' ); ?> <span class="required">*</span></label> |
| 61 | <input type="text" class="input-text" name="first_name" id="tpt_wholesale_first_name" autocomplete="given-name" value="<?php echo esc_attr( $form->value( 'first_name' ) ); ?>" required> |
| 62 | </p> |
| 63 | <p class="form-row <?php echo $form->error( 'last_name' ) ? 'woocommerce-invalid' : ''; ?>"> |
| 64 | <label for="tpt_wholesale_last_name"><?php esc_html_e( 'Last name', 'tier-pricing-table' ); ?> <span class="required">*</span></label> |
| 65 | <input type="text" class="input-text" name="last_name" id="tpt_wholesale_last_name" autocomplete="family-name" value="<?php echo esc_attr( $form->value( 'last_name' ) ); ?>" required> |
| 66 | </p> |
| 67 | </div> |
| 68 | |
| 69 | <p class="form-row <?php echo $form->error( 'email' ) ? 'woocommerce-invalid' : ''; ?>"> |
| 70 | <label for="tpt_wholesale_email"><?php esc_html_e( 'E-mail address', 'tier-pricing-table' ); ?> <span class="required">*</span></label> |
| 71 | <input type="email" class="input-text" name="email" id="tpt_wholesale_email" autocomplete="email" value="<?php echo esc_attr( $form->value( 'email' ) ); ?>" required> |
| 72 | </p> |
| 73 | |
| 74 | <?php if ( $needsPassword ) : ?> |
| 75 | <p class="form-row <?php echo $form->error( 'password' ) ? 'woocommerce-invalid' : ''; ?>"> |
| 76 | <label for="tpt_wholesale_password"><?php esc_html_e( 'Password', 'tier-pricing-table' ); ?> <span class="required">*</span></label> |
| 77 | <input type="password" class="input-text" name="password" id="tpt_wholesale_password" autocomplete="new-password" required> |
| 78 | </p> |
| 79 | <?php endif; ?> |
| 80 | <?php else : ?> |
| 81 | <p class="tpt-wholesale__account"> |
| 82 | <?php |
| 83 | /* translators: 1: user display name, 2: e-mail */ |
| 84 | echo esc_html( sprintf( __( 'Applying as %1$s (%2$s).', 'tier-pricing-table' ), $user->display_name, $user->user_email ) ); |
| 85 | ?> |
| 86 | </p> |
| 87 | <?php endif; ?> |
| 88 | |
| 89 | <?php foreach ( $fields as $field ) : |
| 90 | $key = (string) $field['key']; |
| 91 | $type = (string) $field['type']; |
| 92 | $isRequired = ! empty( $field['required'] ); |
| 93 | $inputId = 'tpt_wholesale_' . $key; |
| 94 | $value = $form->value( $key ); |
| 95 | $rowClass = 'form-row tpt-wholesale__field tpt-wholesale__field--' . $type . ( $form->error( $key ) ? ' woocommerce-invalid' : '' ); |
| 96 | $autofill = array( 'company' => 'organization', 'phone' => 'tel', 'website' => 'url' ); |
| 97 | ?> |
| 98 | <?php if ( 'checkbox' === $type ) : ?> |
| 99 | <p class="<?php echo esc_attr( $rowClass ); ?>"> |
| 100 | <label for="<?php echo esc_attr( $inputId ); ?>" class="tpt-wholesale__checkbox"> |
| 101 | <input type="checkbox" name="<?php echo esc_attr( $key ); ?>" id="<?php echo esc_attr( $inputId ); ?>" value="1" <?php checked( '1', $value ); ?>> |
| 102 | <?php echo esc_html( $field['label'] ); ?> |
| 103 | <?php if ( $isRequired ) : ?><span class="required">*</span><?php endif; ?> |
| 104 | </label> |
| 105 | </p> |
| 106 | <?php continue; ?> |
| 107 | <?php endif; ?> |
| 108 | |
| 109 | <p class="<?php echo esc_attr( $rowClass ); ?>"> |
| 110 | <label for="<?php echo esc_attr( $inputId ); ?>"> |
| 111 | <?php echo esc_html( $field['label'] ); ?> |
| 112 | <?php if ( $isRequired ) : ?><span class="required">*</span><?php else : ?><span class="optional">(<?php esc_html_e( 'optional', 'tier-pricing-table' ); ?>)</span><?php endif; ?> |
| 113 | </label> |
| 114 | <?php if ( 'textarea' === $type ) : ?> |
| 115 | <textarea class="input-text" name="<?php echo esc_attr( $key ); ?>" id="<?php echo esc_attr( $inputId ); ?>" rows="4" <?php echo $isRequired ? 'required' : ''; ?>><?php echo esc_textarea( $value ); ?></textarea> |
| 116 | <?php elseif ( 'select' === $type ) : ?> |
| 117 | <select class="input-text" name="<?php echo esc_attr( $key ); ?>" id="<?php echo esc_attr( $inputId ); ?>" <?php echo $isRequired ? 'required' : ''; ?>> |
| 118 | <option value=""><?php esc_html_e( 'Choose an option…', 'tier-pricing-table' ); ?></option> |
| 119 | <?php foreach ( (array) $field['options'] as $option ) : ?> |
| 120 | <option value="<?php echo esc_attr( $option ); ?>" <?php selected( $option, $value ); ?>><?php echo esc_html( $option ); ?></option> |
| 121 | <?php endforeach; ?> |
| 122 | </select> |
| 123 | <?php else : ?> |
| 124 | <input type="<?php echo esc_attr( 'number' === $type ? 'text' : $type ); ?>" <?php echo 'number' === $type ? 'inputmode="decimal"' : ''; ?> class="input-text" name="<?php echo esc_attr( $key ); ?>" id="<?php echo esc_attr( $inputId ); ?>" value="<?php echo esc_attr( $value ); ?>" <?php echo isset( $autofill[ $key ] ) ? 'autocomplete="' . esc_attr( $autofill[ $key ] ) . '"' : ''; ?> <?php echo $isRequired ? 'required' : ''; ?>> |
| 125 | <?php endif; ?> |
| 126 | </p> |
| 127 | <?php endforeach; ?> |
| 128 | |
| 129 | <?php if ( $termsPageId ) : ?> |
| 130 | <p class="form-row tpt-wholesale__terms <?php echo $form->error( 'terms' ) ? 'woocommerce-invalid' : ''; ?>"> |
| 131 | <label for="tpt_wholesale_terms"> |
| 132 | <input type="checkbox" name="terms" id="tpt_wholesale_terms" value="1" <?php checked( '1', $form->value( 'terms' ) ); ?>> |
| 133 | <?php |
| 134 | echo wp_kses_post( sprintf( |
| 135 | /* translators: %s: link to the terms page */ |
| 136 | __( 'I agree to the %s.', 'tier-pricing-table' ), |
| 137 | '<a href="' . esc_url( get_permalink( $termsPageId ) ) . '" target="_blank" rel="noopener">' . esc_html( get_the_title( $termsPageId ) ) . '</a>' |
| 138 | ) ); |
| 139 | ?> |
| 140 | <span class="required">*</span> |
| 141 | </label> |
| 142 | </p> |
| 143 | <?php endif; ?> |
| 144 | |
| 145 | <?php if ( $recaptchaKey ) : ?> |
| 146 | <input type="hidden" name="g-recaptcha-response" id="tpt_wholesale_recaptcha" value=""> |
| 147 | <?php endif; ?> |
| 148 | |
| 149 | <p class="form-row tpt-wholesale__submit"> |
| 150 | <button type="submit" class="button woocommerce-button"><?php echo esc_html( $submitText ); ?></button> |
| 151 | </p> |
| 152 | |
| 153 | <?php if ( ! $user ) : ?> |
| 154 | <p class="tpt-wholesale__login"> |
| 155 | <?php |
| 156 | echo wp_kses_post( sprintf( |
| 157 | /* translators: %s: login link */ |
| 158 | __( 'Already have an account? %s and apply from there.', 'tier-pricing-table' ), |
| 159 | '<a href="' . esc_url( $loginUrl ) . '">' . esc_html__( 'Log in', 'tier-pricing-table' ) . '</a>' |
| 160 | ) ); |
| 161 | ?> |
| 162 | </p> |
| 163 | <?php endif; ?> |
| 164 | </form> |
| 165 | </div> |
| 166 | |
| 167 | <?php if ( $recaptchaKey ) : ?> |
| 168 | <script> |
| 169 | ( function () { |
| 170 | var form = document.getElementById( <?php echo wp_json_encode( $formId ); ?> ); |
| 171 | if ( ! form ) { return; } |
| 172 | var done = false; |
| 173 | form.addEventListener( 'submit', function ( event ) { |
| 174 | if ( done || typeof grecaptcha === 'undefined' ) { return; } |
| 175 | event.preventDefault(); |
| 176 | grecaptcha.ready( function () { |
| 177 | grecaptcha.execute( <?php echo wp_json_encode( $recaptchaKey ); ?>, { action: 'wholesale_registration' } ).then( function ( token ) { |
| 178 | document.getElementById( 'tpt_wholesale_recaptcha' ).value = token; |
| 179 | done = true; |
| 180 | form.submit(); |
| 181 | } ); |
| 182 | } ); |
| 183 | } ); |
| 184 | } )(); |
| 185 | </script> |
| 186 | <?php endif; ?> |
| 187 |