Last active
November 15, 2020 06:16
-
-
Save dhaupin/7a5d429de5be0d623add58edad51b479 to your computer and use it in GitHub Desktop.
Wordpress shortcode to display WP or Woocommerce login forms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Shortcode - Render Wordpress login form | |
**/ | |
add_shortcode('wp_login_form', function() { | |
if (is_user_logged_in()) { | |
} else { | |
ob_start(); | |
wp_login_form(); | |
return ob_get_clean(); | |
} | |
}); | |
/** | |
* Shortcode - Render Woocommerce login/register form | |
**/ | |
add_shortcode('woocommerce_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, 'woocommerce_login')) { | |
// Add Woocommerce body classes | |
add_filter('body_class', function($body_classes) { | |
$body_classes[] = 'woocommerce-account'; | |
$body_classes[] = 'woocommerce-page'; | |
return $body_classes; | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment