I was recently working on integrating Affiliate WP into one of my friend’s sites. And after I set it up, I was a bit disappointed that the affiliate users would have a separate account page from the WooCommerce users.

For example, users that were checking order history, saved payment details, and more would go to /my-account. But, users that wanted to check their affiliate details would need to go to /affiliates.

The ideal situation seemed to be to add the affiliate page within the WooCommerce “My Account” page. So, I set about on a journey to make that happen.

Some discovery

It’s always nice to find out if others have solved the problem already. And I was in luck, as there were a few tutorials out there that discussed how to add menu items to the WooCommerce “My Account” page 😄 :

Tom writes great stuff, but this article I found of his is simply to add a menu item to the WooCommerce “My Account” page. It does not discuss how to add content to the tab. So, I worked mainly off of Rodolfo Melogli’s article which does cover how to add content to the tab.

What I ended up with

With just a few tweaks, I was able to integrate Affiliate WP in to the WooCommerce “My Account” page. I’ve included some high-level comments that explain what each section is for.

// 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 ;)
function moh_add_aff_wp_link_my_account( $items ) {
  if ( function_exists( 'affwp_is_affiliate' ) && 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' ) ) {
  $shortcode = new Affiliate_WP_Shortcodes;
  echo $shortcode->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 );

Final result

Here are a couple of screenshots demonstrating what this should look like when you’re done.

Closing thoughts

As you can see, just this little bit of code gives us a pretty good visual integration between Affiliate WP and WooCommerce. I found myself asking if Affiliate WP should do this within the plugin, but with how many integrations that they handle, I’m not sure if it would make sense for them.

In the future, and after more testing to make sure that nothing breaks if one of the plugins is not enabled, perhaps this could be factored in to a plugin. Until then, you should be able to get this working by copying the code in to a small plugin on your site or throwing it in the functions.php of your theme.

13 thoughts on “Adding Affiliate WP Dashboard to WooCommerce My Account Page

  1. very helpful – been thinking that this is a method that makes a lot of sense for a while now – if we tried the plugin route, do you happen to know how (what code is required to call the plugin) and where we’d place that (which template files) – thanks in advance, and thanks again for the insight

    1. To get this working as a plugin, the only thing you should need is to add a plugin header which you can read about here: https://codex.wordpress.org/File_Header#Plugin_File_Header_Example

      Then you’d create a directory in wp-content/plugins called something like woo-affiliate-wp-integration. Then you’d create a PHP file called woo-affiliate-wp-integration.php and place the code above in that file. Be sure to add the beginning <?php.

      I’m currently running this on friend’s site as an mu-plugin and haven’t had any issues. Do let me know if you run into issues though.

      1. all seems to be working great – thanks again for the share
        one issue that may be unrelated but the LOGOUT tab at the bottom is not functioning properly, even though the signout text link on the same page seems to work (uses the WOO endpoint)
        … my-account/0/ is where the LOGOUT tab redirects
        whereas the signout redirects to … my-account/customer-logout/ (which works and is the default WC endpoint)

        is there anything in the code that may be causing this OR is it a theme issue

        thanks in advance

  2. I had issues with the log out too. try using:

    // Ensure that the logout link stays at the bottom of the menu 😉
    function moh_add_aff_wp_link_my_account( $items ) {
    if ( function_exists( ‘affwp_is_affiliate’ ) && affwp_is_affiliate() ) {
    array_slice( $items, 0, count( $items ) – 1 ),
    array( ‘aff’ => ‘Affiliate Area’ ),
    array_slice( $items, count( $items ) – 1 )
    return $items;
    add_filter( ‘woocommerce_account_menu_items’, ‘moh_add_aff_wp_link_my_account’ );

    1. ok – thanks – the code above causes a fatal error with the plugin (at least for me)
      – did notice the emojis and removed, but perhaps there is something else that i am missing?

  3. This is great! BTW, getting:

    Warning: Missing argument 1 for Affiliate_WP_Shortcodes::affiliate_area(), called in /nas/content/staging/osana/wp-content/themes/uncode-child/functions.php on line 176 and defined in /nas/content/staging/osana/wp-content/plugins/affiliate-wp/includes/class-shortcodes.php on line 25

    with latest version of AffiliateWP

  4. Hey guys, I notice that you are having trouble with the logout, as it is written in Eric’s code – by the way, thanks for the great post Eric. Here is the issue…

    Change this line:
    $items[] = $logout;

    To this:
    $items[‘customer-logout’] = $logout;

    That should fix it! – Let me know when this works for you.

Leave a Reply