将登录/注销添加到菜单 Woocommerce Wordpress [英] Add login/logout to menu Woocommerce Wordpress

查看:37
本文介绍了将登录/注销添加到菜单 Woocommerce Wordpress的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想弄清楚如何在菜单中添加登录/注销.当我将此代码添加到 wordpress 标题时,内容和侧边栏消失了.如何在不丢失页面其余部分的情况下将登录/注销添加到菜单中.我尝试将它添加到设置菜单中,但它不适用于我正在使用的主题.

I am trying to figure out how to add a login/logout to the menu. When I add this code to the wordpress header the content and sidebar disappear. How can I add the login/logout to the menu without losing the rest of my page. I have tried adding it in the settings menu and it doesn't work with the theme I'm using.

<ul>
<?php
$myaccount_page_id = get_option( 'woocommerce_myaccount_page_id' );
if ( $myaccount_page_id  && !is_user_logged_in()) {
    $myaccount_page_url = get_permalink( $myaccount_page_id );
    ?>
    <li><a href="<?php echo $myaccount_page_url; ?>" class="login-header"><?php _e('Login', 'woocommerce'); ?></a></li>
    <?php
}
$myaccount_page_id = get_option( 'woocommerce_myaccount_page_id' );
if ( $myaccount_page_id && is_user_logged_in()) {
    $logout_url = wp_logout_url( get_permalink( $myaccount_page_id ) );
    if ( get_option( 'woocommerce_force_ssl_checkout' ) == 'yes' )
        $logout_url = str_replace( 'http:', 'https:', $logout_url );
    ?>
    <li><a href="<?php echo $logout_url; ?>" class="login-header"><?php _e('Logout', 'woocommerce'); ?></a></li>
    <?php } ?>
    <li><a href="<?php echo $woocommerce->cart->get_cart_url(); ?>" class="cart-header"><?php _e('Shopping Cart', 'woocommerce'); ?> <?php echo sprintf(_n('(%d)', '(%d)', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?></a></li>
    <li><a href="<?php echo $woocommerce->cart->get_checkout_url(); ?>" class="check-header"><?php _e('Checkout', 'woocommerce'); ?></a></li>
</ul>

推荐答案

如果你使用像 主题我的登录 您只需在菜单中创建登录页面的链接即可.如果此人未登录,它将显示登录",如果此人已登录,它将显示注销".希望这有帮助!

If you use a plugin like Theme My Login you can just create the link to the login page in your menu. It will display "Login" if the person is not logged in, and "Log Out" if the person is logged in. Hope this helps!

这篇关于将登录/注销添加到菜单 Woocommerce Wordpress的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆