最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

menus - unable to add custom pagetab to my account woocommerce

programmeradmin2浏览0评论

I have been trying over and over but have come up empty handed. I have followed this tutorial (/) 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 :)

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 :)

Share Improve this question edited Jul 4, 2018 at 16:47 fuxia 107k38 gold badges255 silver badges459 bronze badges asked Jun 7, 2018 at 4:08 NRavNRav 1132 silver badges6 bronze badges 2
  • the hook that display the page content must be called woocommerce_account_earnings_endpoint and not "woocommerce_earnings_endpoint". – mmm Commented Jun 7, 2018 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 Commented Jun 7, 2018 at 13:30
Add a comment  | 

2 Answers 2

Reset to default 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();

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 );
发布评论

评论列表(0)

  1. 暂无评论