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 |2 Answers
Reset to default 1Try 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 );
woocommerce_account_earnings_endpoint
and not "woocommerce_earnings_endpoint". – mmm Commented Jun 7, 2018 at 5:33