dtrn74832 2016-07-27 08:13
浏览 110
已采纳

如何替换我的帐户并在Woocommerce中添加登录/注销链接到菜单?

I am using woocommerce and I add the one menu My Account using woocommerce plugin But I want to show the menu login and logout instead of My Account which I add the into menu. I also added the script into functions.php result is same.

add_filter( 'wp_nav_menu_items', 'add_loginout_link', 10, 2 );

function add_loginout_link( $items, $args ) {

   if (is_user_logged_in() && $args->theme_location == 'primary_navigation') {

       //echo "hello friend how are";

       $items .= '<li><a href="'. wp_logout_url( get_permalink( woocommerce_get_page_id( 'myaccount' ) ) ) .'">Log Out</a></li>';

   }

   elseif (!is_user_logged_in() && $args->theme_location == 'primary_navigation') {

       $items .= '<li><a href="' . get_permalink( woocommerce_get_page_id( 'myaccount' ) ) . '">Log In</a></li>';

   }

   return $items;

}

When I am using jupitor theme and when I see the theme location of My Account Menu I get

Primary Navigation I have a one doubt is I have to add the My Account menu first then I add the login and logout menu.

  • 写回答

1条回答 默认 最新

  • dongmi1221 2016-07-27 10:15
    关注

    Your above code will add login/logout links to menu. You do not have to add My Account menu.

    Please check your theme_location. If theme location is correct then login/logout link will add to menu.

    For check theme_location you have to search register_nav_menus in functions.php file of your theme. If you find it in functions.php file then you can see theme_location inside register_nav_menus code.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?