How to create separate log-in and registration pages in WooCommerce - wordpress

I want to seperate the login and registration page for woocommerce.
(there is a different solution that I don't get to work here:
Separate registration page in WooCommerce website)
I duplicated the form-login.php and renamed it to register.php
In the register.php template I deleted the login-content.
I want to add a page to wordpress and add the register.php template with a SHORTCODE to that page. How do I do this??
Then I could add a Register Link to the Login Page with
<?php _e( ' Register' ); ?>
and the new shortcode register page is loaded.
mmmhhh...
what do I have to add to the duplicated login /now register.php, that it can be loaded to any page with a SHORTCODE? that would be interesting.
Thanks for helping out!Best wishes, Mika

A more straightforward way to do this is to save the contents of the original form-login.php as form-login-single.php, and then replace the file form-login.php with:
<?php
if( isset($_GET['action']) == 'register' ) {
wc_get_template( 'myaccount/form-register.php' );
} else {
wc_get_template( 'myaccount/form-login-single.php' );
}
This way you don't need to modify your functions.php further, plus you don't run into any trouble with double-rendering of the register form that I got when using #Hassan-ALi's method.

You can create a copy of the Woocommerce form-login.php and name it form-register.php. The form-login.php is located in /woocommerce/templates/myaccount/ folder.
Then in the form-login.php you can create a link to the form-register.php using this code
register
// Separete Login form and registration form
add_action('woocommerce_before_customer_login_form','load_registration_form', 2);
function load_registration_form(){
if(isset($_GET['action'])=='register'){
woocommerce_get_template( 'myaccount/form-registration.php' );
}
}

Related

How to redirect user to another page if the user is logged in - WordPress Elementor Page Builder

I have created a registration form using Elementor Page Builder. Now, I want to redirect the user to a different page if he/she is trying to access that registration page after logging in.
Is there any Elementor hook available for that? I know the WordPress function called is_user_logged_in().
function my_logged_in_redirect() {
if ( is_user_logged_in() && is_page( 12 ) )
{
wp_redirect( get_permalink( 32 ) );
die;
}
}
add_action( 'template_redirect', 'my_logged_in_redirect' );
You should get the ids of the page where the form is and the id of the page you want to redirect the user to.
Code goes in your child theme functions.php file
Reference: here
The 'Content Area Not Found' error might appear on Elementor designed sites when you use that snippet and try to edit page of ID 12 (in your example) in certain cases.
To avoid this, add the following code before the if-statement of your snippet:
if ( \Elementor\Plugin::$instance->preview->is_preview_mode() ) {
return;
}

Wordpress - Is it possible to do a request to the wordpress database from a page html block?

I am new to WordPress.org and I figured out that I can add HTML, CSS and Javascript to a page via a code block. But my question is, can I also make a call to the WordPress database from a page? Or do I need to make a plugin for that?
You can do this with a shortcode that calls a php function in your (child-themes) functions.php.
This is a good guide to start from:
https://www.wpbeginner.com/wp-tutorials/how-to-add-a-shortcode-in-wordpress/
// function that runs when shortcode is called
function wpb_demo_shortcode() {
// Things that you want to do.
$message = 'Hello world!';
// Output needs to be return
return $message;
}
// register shortcode
add_shortcode('greeting', 'wpb_demo_shortcode');
And then call it within your post/page (in a Gutenberg shortcode block)
[greeting]
This is a good way because you can re-use and maintain it easily.
Tom
Using page you can call database you can do it using
Creating a template and assign that template in wordpress page
Or you can create short code in function.php and add shortcode in your wordpress page
Create page template
1) Create file in your theme folder and name it 'custom.php' you can name it anything.
2) Open file and add this
3) Start editing in that page you can call database using
global $wpdb;
$result = $wpdb->get_results('SELECT * FROM wp_posts LIMIT 10');
4) After editing 'custom.php' you can assign this template in your custom page
note: please refer this link to know more about page template
https://www.cloudways.com/blog/creating-custom-page-template-in-wordpress/
Create short code in function.php
1) You can create shortcode using
// function that runs when shortcode is called
function wpb_demo_shortcode() {
global $wpdb;
$result = $wpdb->get_results('SELECT * FROM wp_posts LIMIT 10');
return $result;
}
// register shortcode
add_shortcode('get_post_shortcode', 'wpb_demo_shortcode');
2) you can call shortcode in any page of wordpress.
<?php echo do_shortcode("[get_post_shortcode]"); ?>

How to remove wordpress date archive pages?

I have developed my own wordpress theme, and learning all kinds of programming stuff, but my priority is the content, not the programming knownledge. I need to know how to remove archive date listing from wordpress?
Question 1: The google search results displayed like this: virmodrosti.com/2017/05/
I don't want any kind of date archive option, how do you disable that?
I also don't use any kind of plugin, and always like to do it on my own.
Question 2: I don't know why older entries doesn't work anymore
virmodrosti.com/zdravje/ this page works fine
virmodrosti.com/zdravje/page/2/ it redirects to 404 error page
I only choose option in wordpress to hide that annoying /category/ with dash . inside editor at permanlinks, Category base. Maybe somehow these stuff is kinda fighting with each other and doesn't work properly.
Thank you.
This is code from Digital Nomad theme I maintain:
function digitalnomad_remove_date_archives() {
//if we are on date archive page
if ( is_date() ) {
// theme sets alternatine archive page with table like list of all posts
$archive_page = get_option( 'digitalnomad_archive_page' );
if ( $archive_page ) {
// redirs to alternatine archive page if configured (good for SEO)
wp_redirect( esc_url( get_page_link( $archive_page ) ) );
die();
} else {
// otherwise error 404 is displayed
global $wp_query;
$wp_query->set_404();
}
}
}
add_action( 'template_redirect', 'digitalnomad_remove_date_archives' );
Use the smart Archive Page Remover wordpress plugin
or visit your theme's functions.php file
then insert this code
/* Register template redirect action callback */
add_action('template_redirect','makes_remove_wp_archives');
/* Remove archive*/
function makes_remove_wp_archives(){
// if we are on category or tag or date or author archive
if(is_category()|| is_tag()||is_author()){
global $wp_query;
$wp_query->set_404();
}
}

How to Disable Woocommerce My Account Autodirect

I'd like to customize the Woocommerce login/register page using an editor plugin which requires you to be logged into the Wordpress Dashboard. The problem is Woocommerce directs to the My Account page if the user is logged in. Is there a snippet I could temporarily run that will tell Woocommerce to load the login/register page instead of the My Account page if the user is logged in?
I found a solution thanks to a reply Oliver Vogel made to someone else asking the same question here. Thanks Oliver! This is Oliver's Post
For non-technical people like me who are trying to edit the Woocommerce Login / Register page while being logged into the Wordpress dashboard, insert this snippet into the functions.php file preferably with a nice plugin like Code Snippets. It will create a shortcode called [woo-login]. Create a new web page and add the [woo-login] shortcode to it and the Woo login page will open even when you are logged in.
add_shortcode('woo-login', 'my_login');
function my_login() {
if (is_user_logged_in()) {
ob_start();
echo '<div class="woocommerce">';
wc_get_template('myaccount/form-login.php');
echo '</div>';
return ob_get_clean();
} else {
ob_start();
echo '<div class="woocommerce">';
wc_get_template('myaccount/form-login.php');
echo '</div>';
return ob_get_clean();
}
}

Wordpress Multisite : Default page for newly created site

I am new to wordpress multisite.
whenever I create a new sub-site and visit that sub-site it show 'Welcome to %s. This is your first post. Edit or delete it, then start blogging!'
My problem is I want to set a sample(Default)page for all the newly created sub-sit with custom text menu and theme instead of their default post.
is there any plugin that can help.
So my question is how to set sample(Default) page for each sub-site? instead of setting those page manually.
Any way to get rid of this issue?
Thanks!
By default, wordpress shows the latest posts page as front page when you create a new site
You can change that by going to Settings > Reading.
or you can use Refrence action:
function wporg_wpmu_new_blog_example( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {
global $switched;
switch_to_blog($blog_id);
update_option('page_on_front', 'sample page id');
restore_current_blog();
}
add_action( 'wpmu_new_blog', 'wporg_wpmu_new_blog_example', 10, 6 );

Resources