I want to show the woocommerce login and register page but without the options when an user is logged in.
In former versions you could use a shortcode but now you have to use [my_account]. When an user is logged in, he sees his account information.
Are there any hooks / functions to show the register and login forms?
Thanks
Maddin
i know, the question is a little bit older...
Try this:
add_shortcode('woo-login', 'my_login');
function my_login() {
if (is_user_logged_in()) {
// Do what you want...
} else {
ob_start();
echo '<div class="woocommerce">';
wc_get_template('myaccount/form-login.php');
echo '</div>';
return ob_get_clean();
}
}
Although Oliver's code works, it's now missing a couple Woocommerce styles and subsequent JS that WP uses to render the form correctly. Perhaps they added these since the answer was posted. This snippet adds relevent <body>
classes if the woo-login
shortcode is used.
/**
* Shortcode - Render Woocommerce login/register form
**/
add_shortcode('woo-login', function() {
if (is_user_logged_in()) {
} else {
ob_start();
echo '<div class="woocommerce">';
wc_get_template('myaccount/form-login.php');
echo '</div>';
return ob_get_clean();
}
});
/**
* Mitigate theme before render
**/
add_action('template_redirect', function() {
global $post;
if (has_shortcode($post->post_content, 'woo-login')) {
// Add Woocommerce body classes
add_filter('body_class', function($body_classes) {
$body_classes[] = 'woocommerce-account';
$body_classes[] = 'woocommerce-page';
return $body_classes;
});
}
});
Heres a link to the Gist: https://gist.github.com/dhaupin/7a5d429de5be0d623add58edad51b479