Kaz*_*edi 1 wordpress woocommerce
我想在用户未登录时将 woocommerce 结帐页面重定向到我的帐户页面。
我试过了,但它不起作用
<?php
function my_page_template_redirect()
{
$checkouturl = home_url( '/checkout/' );
if( is_page($checkouturl) && ! is_user_logged_in() )
{
wp_redirect( home_url( '/my-account/' ) );
exit();
}
}
add_action( 'template_redirect', 'my_page_template_redirect' );
?>Run Code Online (Sandbox Code Playgroud)
提前致谢
以下是重定向未登录 woocommerce 页面的用户的代码
function wpse_131562_redirect() {
if (
! is_user_logged_in()
&& (is_cart() || is_checkout())
) {
// feel free to customize the following line to suit your needs
wp_redirect(wp_login_url());
exit;
}
}
add_action('template_redirect', 'wpse_131562_redirect');
Run Code Online (Sandbox Code Playgroud)
将此代码放入您的主题中functions.php,它将起作用
| 归档时间: |
|
| 查看次数: |
8696 次 |
| 最近记录: |