As you most likely are aware, the WooCommerce My Account page, which contains the shortcode, has both Login and Registration structures. In any case, this isn’t constantly a smart thought, for the most part when you use points of arrival or deals pages with a particular objective for example client enrollment.
Obviously, when this occurs, you would prefer not to have a login structure there also. My answer gives two new shortcodes, one for the login structure and one for the register structure.
If it’s not too much trouble know both shortcodes’ substance is replicated from WooCommerce format records – if WooCommerce discharges an update or rolls out an improvement to these documents, you have to change the shortcode coding as well.
What to do before utilizing the shortcodes below.
As you probably are aware, the [woocommerce_my_account]
shortcode is a significant one and must be kept on the WooCommerce My Account page no matter what.
This implies, in the event that you need to keep the login structure AND the “My Account” dashboard while signed in agreement, simply continue utilizing [woocommerce_my_account] for that, together with Snippet #1.
To recap, in the event that you need to have LOGIN + MY ACCOUNT, and a different REGISTRATION page, utilize these 2 shortcodes and Snippet #1:
[wc_reg_form_bbloomer]
on the Register Page
[woocommerce_my_account]
on the Login/My Account Page
On the off chance that you need to have separate LOGIN, REGISTRATION and MY ACCOUNT pages then you need 3 shortcodes:
[wc_reg_form_wbcomdesign]
on the Register Page
[wc_login_form_wbcomdesign]
on the Login Page
[woocommerce_my_account]
on the My Account Page
In the both cases, you have to disable “Enable clients to make an account on the “My account” page”:
WooCommerce Customer Registration (Shortcode).
[php]
//This will create a new Shortcode: [wc_reg_form_wbcomdesign]
add_shortcode( ‘wc_reg_form_wbcomdesign’, ‘wbcomdesign_separate_registration_form’ );
function wbcomdesign_separate_registration_form() {
if ( is_admin() ) return;
if ( is_user_logged_in() ) return;
ob_start();
[/php]
Note: This code is copied from woocommerce\templates\myaccount\form-login.php
[php]
?>
<form method=”post” class=”woocommerce-form woocommerce-form-register register” <?php do_action( ‘woocommerce_register_form_tag’ ); ?> >
<?php do_action( ‘woocommerce_register_form_start’ ); ?>
<?php if ( ‘no’ === get_option( ‘woocommerce_registration_generate_username’ ) ) : ?>
<p class=”woocommerce-form-row woocommerce-form-row–wide form-row form-row-wide”>
<label for=”reg_username”><?php esc_html_e( ‘Username’, ‘woocommerce’ ); ?> <span class=”required”>*</span></label>
<input type=”text” class=”woocommerce-Input woocommerce-Input–text input-text” name=”username” id=”reg_username” autocomplete=”username” value=”<?php echo ( ! empty( $_POST[‘username’] ) ) ? esc_attr( wp_unslash( $_POST[‘username’] ) ) : ”; ?>” /><?php // @codingStandardsIgnoreLine ?>
</p>
<?php endif; ?>
<p class=”woocommerce-form-row woocommerce-form-row–wide form-row form-row-wide”>
<label for=”reg_email”><?php esc_html_e( ‘Email address’, ‘woocommerce’ ); ?> <span class=”required”>*</span></label>
<input type=”email” class=”woocommerce-Input woocommerce-Input–text input-text” name=”email” id=”reg_email” autocomplete=”email” value=”<?php echo ( ! empty( $_POST[’email’] ) ) ? esc_attr( wp_unslash( $_POST[’email’] ) ) : ”; ?>” /><?php // @codingStandardsIgnoreLine ?>
</p>
<?php if ( ‘no’ === get_option( ‘woocommerce_registration_generate_password’ ) ) : ?>
<p class=”woocommerce-form-row woocommerce-form-row–wide form-row form-row-wide”>
<label for=”reg_password”><?php esc_html_e( ‘Password’, ‘woocommerce’ ); ?> <span class=”required”>*</span></label>
<input type=”password” class=”woocommerce-Input woocommerce-Input–text input-text” name=”password” id=”reg_password” autocomplete=”new-password” />
</p>
<?php else : ?>
<p><?php esc_html_e( ‘A password will be sent to your email address.’, ‘woocommerce’ ); ?></p>
<?php endif; ?>
<?php do_action( ‘woocommerce_register_form’ ); ?>
<p class=”woocommerce-FormRow form-row”>
<?php wp_nonce_field( ‘woocommerce-register’, ‘woocommerce-register-nonce’ ); ?>
<button type=”submit” class=”woocommerce-Button button” name=”register” value=”<?php esc_attr_e( ‘Register’, ‘woocommerce’ ); ?>”><?php esc_html_e( ‘Register’, ‘woocommerce’ ); ?></button>
</p>
<?php do_action( ‘woocommerce_register_form_end’ ); ?>
</form>
<?php
return ob_get_clean();
}
[/php]
Now, Separate the Login (Shortcode) in WooCommerce
You have to read the notes above – you probably won’t require this shortcode at all and [woocommerce_my_account] might be adequate to show the login form.
[php]
//This will create a new Shortcode:[wc_login_form_wbcomdesign]
add_shortcode( ‘wc_login_form_wbcomdesign’, ‘wbcomdesign_separate_login_form’ );
function wbcomdesign_separate_login_form() {
if ( is_admin() ) return;
if ( is_user_logged_in() ) return;
ob_start();
woocommerce_login_form();
return ob_get_clean();
}
[/php]
Also read: How To Add Content To The Thank You Page in WooCommerce?