简体   繁体   English

Woocommerce Checkout后注销用户

[英]Logout user after Woocommerce Checkout

using Woocommerce, is it possible to Force a user to be Logged out directly after Checkout (IMPORTANT: I need to have 'Allow customers to create an account during checkout' ticked.) 使用Woocommerce,是否可以强制在结帐后直接注销用户(重要说明:我需要勾选“允许客户在结帐时创建帐户”)。

I ask because by default a user purchases an online course and they get direct access to it despite not being verified by an Admin user. 我想问一下,因为默认情况下,用户购买了在线课程,尽管管理员未进行验证,但他们可以直接访问该课程。

You can use logout function after checkout order 您可以在结帐后使用注销功能

add_action('woocommerce_payment_complete', 'custom_process_order', 10, 1);

function custom_process_order() {   
wp_logout();
}

The following will logout customer after checkout redirecting customer to shop page: 在结帐将客户重定向到商店页面后,以下内容将注销客户:

// Logourt after checkout and redirect to shop
add_action( 'template_redirect', 'order_received_logout_redirect' );
function order_received_logout_redirect() {
    // Only on "Order received" page
    if( is_wc_endpoint_url('order-received') ) {
        wp_logout(); // Logout

        // Shop redirection url
        $redirect_url = get_permalink( get_option('woocommerce_shop_page_id') );

        wp_redirect($redirect_url); // Redirect to shop

        exit(); // Always exit
    }
}

Code goes in function.php file of your active child theme (or active theme). 代码进入您的活动子主题(或活动主题)的function.php文件中。 Tested and work. 经过测试和工作。

Note: When a customer is logged out, it can't access anymore the order summary (Order received) after checkout, so a redirection is required. 注意:注销客户后,结帐后将无法再访问订单摘要(已收到订单),因此需要重定向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM