将Affiliate WP仪表盘添加到WooCommerce我的帐户页面

我最近正致力于将Affiliate WP整合到我朋友的一个网站中。在我设置之后,我对联盟用户和WooCommerce用户的帐户页面是两个不同的页面感到有点失望。

例如,检查订单历史记录,保存的付款详细信息等的用户将会访问/my-account。但是,想要查看其联盟用户详细信息的用户需要访问/affiliates

理想情况似乎是在WooCommerce“我的帐户”页面中添加联盟页面。所以,我开始着手实现这一目标。

一些发现

总是很高兴找出其他人是否已经解决了这个问题。我很幸运,因为有一些教程讨论了如何将菜单项添加到WooCommerce“我的帐户”页面?

Tom写了很多东西,但是我发现他的这篇文章只是将一个菜单项添加到WooCommerce“我的帐户”页面。它没有讨论如何向选项卡添加内容。因此,我主要从Rodolfo Melogli的文章开始,该文章介绍了如何向标签添加内容。

我最终得到了什么

通过一些调整,我能够将Affiliate WP整合到WooCommerce“我的帐户”页面中。我已经包含了一些高级别的评论来解释每个部分的用途。

// Add the rewrite endpoint so that we don't 404 on the new My Account tab

function moh_add_aff_wp_endpoint() {

  add_rewrite_endpoint( 'aff', EP_ROOT | EP_PAGES );

}

add_action( 'init', 'moh_add_aff_wp_endpoint' );



// Add the new affiliate area link to the "My Account" menu

// if Affiliate WP is enabled and the current user is an affiliate.

//

// Ensure that the logout link stays at the bottom of the menu <img draggable="false" class="emoji" alt="" src="https://s.w.org/images/core/emoji/11.2.0/svg/1f609.svg">

function moh_add_aff_wp_link_my_account( $items ) {

  if ( function_exists( 'affwp_is_affiliate' ) &amp;&amp; affwp_is_affiliate() ) {

    $logout = array_pop( $items );

    $items['aff'] = 'Affiliate Area';

    $items[] = $logout;

  }

  return $items;

}

add_filter( 'woocommerce_account_menu_items', 'moh_add_aff_wp_link_my_account' );



// Render the Affiliate WP Content within the new tab if Affiliate WP is enabled

function moh_aff_wp_content() {

  if ( ! class_exists( 'Affiliate_WP_Shortcodes' ) ) {

    return;

  }

  $shortcode = new Affiliate_WP_Shortcodes;

  echo $shortcode-&gt;affiliate_area();

}

add_action( 'woocommerce_account_aff_endpoint', 'moh_aff_wp_content' );



// Make sure that the Affiliate WP tabs properly work

function moh_filter_aff_tabs( $url, $page_id, $tab ) {

  return esc_url_raw( add_query_arg( 'tab', $tab ) );

}

add_filter( 'affwp_affiliate_area_page_url', 'moh_filter_aff_tabs', 10, 3 );

最后结果

以下是一些屏幕截图,展示了完成后应该是什么样子。

加盟WP URL选项卡

加盟WP统计选项卡

这是Affiliate WP统计信息选项卡,集成在WooCommerce“我的帐户”页面中。

最后结果

正如您所看到的,只需这一点代码就可以为Affiliate WPWooCommerce提供相当好的集成。

在将来,并且经过更多测试以确保在没有启用其中一个插件的情况下没有任何中断,也许这可能会被插入到插件中。在此之前,您应该可以通过将代码复制到您网站上的小插件或将其放入functions.php主题中来实现此功能。

点击查看原文

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值