我已经试了一遍又一遍,但都是空手而归。我已经学习了本教程(https://www.atomicsmash.co.uk/blog/customising-the-woocommerce-my-account-section/) 为“我的帐户”菜单创建新的php页面。由于某些原因,它将不会链接到新端点并不断恢复到仪表板。。。
下面是我添加到主题函数中的代码。php文件;
/**
* 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\' );
我也多次保存和刷新永久链接设置。。。没有运气。我添加的新页面位于woocommerce/templates/myaccount/earnings中。php
收益。php页面就是这样,所以我知道何时以及是否得到它;
<?php
echo ‘HELLO MOM’;
提前感谢:)
SO网友:peroks
尝试将此代码添加到add_action\'init\'函数中。
// 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();