Woocommerce can't disable Guest Checkout - wordpress

I am using Woocommerce and am having problems disabling the guest checkout.
I have made sure 'Enable Guest Checkout' is unticked in the settings page but people are still able to checkout without creating an account or logging in.
Is there somewhere else I should be setting this?

Go to WooCommerce > Accounts and untick Enable registration on the "Checkout" page.
This should do the job!
Alternatively, you can add this code to your theme functions.php
add_action( 'template_redirect', 'woo_restirct_checkout' );
function woo_restirct_checkout() {
if ( !is_user_logged_in() && is_checkout() ) {
$my_account_url = get_permalink( get_option('woocommerce_myaccount_page_id') );
wp_redirect( $my_account_url );
exit;
}
}
Cheers,
Francesco

Also need to unticked the option from Woocommerce -> Accounts tab.
Where it says Enable registration on the "Checkout" page.

Try looking at the site in a different browser from the one you're developing on. I found that being logged in as a user in wordpress-admin, also made me an active, logged in user for the checkout.

Related

How to create redirect for log in modal

I'm trying to redirect this login button to a different page upon log in success. How do I do that without a plugin?
I tried checking the Woo Commerce settings and LearnDash settings and it does not change. I tried looking in the PHP file but am not really sure where to start.
picture of login modal
You can use the filter "woocommerce_login_redirect", which will redirect the user after successful login.
Follow the code below:
add_filter( 'woocommerce_login_redirect', 'my_login_redirect' );
function my_login_redirect( $redirect_to ) {
$redirect_to = 'http://www.example.com/my-account/';
return $redirect_to;
}
Hope this will help!

Endpoints not working on WooCommerce checkout page

I developing a custom theme. I have an issue on checkout page. When I click on 'Place order' button the URL of checkout page changing from http://localhost/sitename/checkout to look like http://localhost/sitename/checkout/order-received/390/?key=wc_order_DvIkeeaIUoNFI if payment-method is 'Cash on delivery' or http://localhost/sitename/checkout/order-pay/391/?key=wc_order_2TbWibkoOZcxz&order=391 if I choose Internet acquiring payment-method.
But on that pages displayed content of checkout page. I think that endpoints don't work.
Here is what I did to fix that issue:
Checked endpoints in WooCommerce -> Settings -> Advanced
Created new checkout page and deleted old
Checked Chrome DevTools Console for JS errors
Turned off all plugins except for WooCommerce. Issue still exists.
Checked it on another test-site with Storefront theme. Everything works.
Checked all default Woocommerce hooks in my custom checkout templates. There are available.
Create web.configfile in site's directory with code which provides on https://woocommerce.com/document/woocommerce-endpoints-2-1/
Trying to redirect with this code:
<?php
add_action( 'template_redirect', 'woo_custom_redirect_after_purchase' );
function woo_custom_redirect_after_purchase() {
global $wp;
if ( is_checkout() && !empty( $wp->query_vars['order-received'] ) ) {
wp_redirect( home_url('/thank-you') );
exit;
}
if ( is_checkout() && !empty( $wp->query_vars['order-pay'] ) ) {
wp_redirect( 'https://secure.wayforpay.com/pay' );
exit;
}
}
?>
As for me it's bad solution. Because if payment-method is 'Cash on delivery' on thank you page it is not possible to get order data, and if method is 'Internet acquiring' I need to get and transfer order data to acquiring system, but I have a plugin which should do it without my participation. And plugin working on another test-site.
This issue is very popular among junior Wordpress-developers, but there is few information about solving this problem.
I think that endpoints works incorrect, but I don't know how to fix it.
I will be very grateful if you share your own experience in solving the problem or tell me what to look for.
Updated
In addition I compared requests and responds in Chrome->DevTools->Network between site with Storefront theme and my site. They are the same, but on my site the redirect is not happening.
I fixed it.
Main issue consist in that my woocommerce doesn't do shortcodes from Console->Pages, so I activated checkout template via page-checkout.php where I get template part form-checkout.php (get_template_part( 'woocommerce/checkout/form-checkout' );).
To fix a bug I replaced this string with echo do_shortcode(['woocommerce_checkout']);.
Very simple solution that I spent almost 3 days searching for, but even better I learned how wordpress works

Login issue using dokan and revo wp theme

i installed dokan multi vendor plugin and revo theme on wordpress, whenever i use the multi-vendor account to login using the login widget, it takes to me the customer dashboard.
but on the regular login page ,it takes me to the correct url
I tried placing this code in themes/functions.php but didn't help, Pls I need assistance
add_filter( 'woocommerce_login_redirect', 'ckc_login_redirect', 10, 2 );
function ckc_login_redirect( $redirect_url, $user ) {
// Change this to the url to Updates page
if( $user->roles[0] == 'seller' ) {
return dokan_get_navigation_url(‘dashboard’);
}
return $redirect_url;
}
As you are not using the WooCommerce default my-account page for that reason, your vendor is not redirecting to the Dashboard page. I beleive that your theme login widget is using the default WordPress login function. So, I will suggest you to follow this function reference to redirect vendor to dashboard-https://codex.wordpress.org/Plugin_API/Filter_Reference/login_redirect
Thanks :)

hide popup maker plugin link from wordpress

I installed pop up maker and capabilities plugin in wordpress for my website. I want to create one user who is not able to see the link for pop up maker. I tried with adding user with some capability but I am not able to hide pop up maker link.
How can I achieve this? Do I need to use another capability plugin?
You can use the remove_menu_page() function called via the admin_menu action hook. If you just want to remove the link for a single user, check the current user's ID first with wp_get_current_user().
function remove_admin_menu_item_for_user() {
$user = wp_get_current_user();
// Check to see if the current user's ID is the one we want to remove the page for
if ( $user->ID == ??? ){
// Use the $menu_slug for the page you want to remove
remove_menu_page( $menu_slug );
}
}
add_action( 'admin_menu', 'remove_admin_menu_item_for_user' );
If you would prefer to use a plugin Admin Menu Editor should work as well, though you may need the Pro version.

Woocommerce Wordpress Plugin Change the Checkout Flow

I am using Woocommerce wordpress plugin in my site. When I am in the Cart page and click "proceed to checkout" I am now going to checkout page. I want to change this flow as below.
If the user is not logged in, he should be taken to a different url. If user is logged in he will go to checkout page as usual.
Any help is appreciated.
First you create a page where you want to redirect the guest user, for example register
then write this code in your functions.php
function restrict_user() {
if (! is_user_logged_in() && (is_checkout())) {
wp_redirect("http://your site url.com/register/");
exit;
}
}
add_action('template_redirect', 'restrict_user');
Hope this will help you...

Resources