0

I have been trying over and over but have come up empty handed. I have followed this tutorial (https://www.atomicsmash.co.uk/blog/customising-the-woocommerce-my-account-section/) to create a new php page for 'My accounts' menu. for some reason it will not link to the new endpoint and constantly revert to dashboard...

here is the code I have added to my themes function.php file;

/**
  * Register new endpoints to use inside My Account page.
  */

 add_action( 'init', 'my_account_new_endpoints' );

 function my_account_new_endpoints() {
    add_rewrite_endpoint( 'earnings', EP_ROOT | EP_PAGES );
 }
/**
  * Get new endpoint content
  */

  // Awards
 add_action( 'woocommerce_earnings_endpoint', 'earnings_endpoint_content' );
 function earnings_endpoint_content() {
     get_template_part('earnings');
 }
/**
  * Edit my account menu order
  */

 function my_account_menu_order() {
    $menuOrder = array(
        'dashboard'          => __( 'Dashboard', 'woocommerce' ),
    'orders'             => __( 'Your Orders', 'woocommerce' ),
        'earnings'             => __( 'Earnings', 'woocommerce' ),
        //'downloads'          => __( 'Download', 'woocommerce' ),
        'edit-address'       => __( 'Addresses', 'woocommerce' ),
        'edit-account'      => __( 'Account Details', 'woocommerce' ),
        'customer-logout'    => __( 'Logout', 'woocommerce' ),
    );
    return $menuOrder;
 }
 add_filter ( 'woocommerce_account_menu_items', 'my_account_menu_order' );

I have saved and flushed the permalinks settings multiple times too... no luck. The new page I have added is in woocommerce/templates/myaccount/earnings.php

the earnings.php page simply has this so I know when and if I get it;

<?php

echo ‘HELLO MOM’;

Thank you in advance :)

2
  • the hook that display the page content must be called woocommerce_account_earnings_endpoint and not "woocommerce_earnings_endpoint".
    – mmm
    Jun 7 '18 at 5:33
  • @mmm I still get nothing.... I click the new menu item and it goes no where now. just a blank page
    – NRav
    Jun 7 '18 at 13:30
1

Try adding this code to your add_action 'init' function.

//  Let WooCommerce add a new custom endpoint "earnings" for you
add_filter( 'woocommerce_get_query_vars', function( $vars ) {
    $vars['earnings'] = 'earnings';
    return $vars;
} );

//  Add "earnings" to the WooCommerce account menu
add_filter( 'woocommerce_account_menu_items', function( $items ) {
    $items['earnings'] = __( 'My earnings', 'your-text-domain' );
    return $items;
} );

//  Display your custom title on the new endpoint page
//  Pattern: woocommerce_endpoint_{$your_endpoint}_title
add_filter( 'woocommerce_endpoint_earnings_title', function( $title ) {
    return __( 'My earnings', 'your-text-domain' );
} );

//  Display your custom content on the new endpoint page
//  Pattern: woocommerce_account_{$your_endpoint}_endpoint
add_action( 'woocommerce_account_earnings_endpoint', function() {
    echo __( 'Hello World', 'your-text-domain' );
} );

//  Only for testing, REMOVE afterwards!
flush_rewrite_rules();
0

In your code, you have not added endpoint to query vars.

Missing code:

function custom_query_vars( $vars ) {
    $vars[] = 'earnings';
    return $vars;
}
add_filter( 'query_vars', 'custom_query_vars', 0 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.