Woocommerce Checkout 后注销用户
Logout user after Woocommerce Checkout
使用 Woocommerce,是否可以强制用户在结帐后直接注销(重要:我需要勾选 'Allow customers to create an account during checkout'。)
我问是因为默认情况下用户购买了在线课程并且他们可以直接访问它,尽管没有经过管理员用户的验证。
结账订单后可使用登出功能
add_action('woocommerce_payment_complete', 'custom_process_order', 10, 1);
function custom_process_order() {
wp_logout();
}
以下将在结帐后将客户重定向到商店页面后注销客户:
// 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
}
}
代码进入您的活动子主题(或活动主题)的 function.php 文件。测试和工作。
Note: When a customer is logged out, it can't access anymore the order summary (Order received) after checkout, so a redirection is required.
使用 Woocommerce,是否可以强制用户在结帐后直接注销(重要:我需要勾选 'Allow customers to create an account during checkout'。)
我问是因为默认情况下用户购买了在线课程并且他们可以直接访问它,尽管没有经过管理员用户的验证。
结账订单后可使用登出功能
add_action('woocommerce_payment_complete', 'custom_process_order', 10, 1);
function custom_process_order() {
wp_logout();
}
以下将在结帐后将客户重定向到商店页面后注销客户:
// 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
}
}
代码进入您的活动子主题(或活动主题)的 function.php 文件。测试和工作。
Note: When a customer is logged out, it can't access anymore the order summary (Order received) after checkout, so a redirection is required.