WooCommerce - 将端点分配给我的帐户页面中的多个自定义模板

WooCommerce - Assign endpoints to multiple custom templates in my-account page

我正在尝试添加 2 个端点并将它们与两个自定义模板相关联。 'my-server' -> 'Servers''my-affiliate -> 'Affiliate'.

我还创建了两个自定义模板:

它们都位于我的 theme > woocommerce > myaccount 文件夹中。附属页面正确指向 url/myaccount/my-affiliate

But my problem is that Servers is giving "404 page not found" error.

我已尝试使用此线程中的解决方案:

理想情况下,我应该要求将此作为评论,但我没有足够的声誉来发表评论DarioFerrer 的解决方案非常适合单个端点和单个自定义模板。

就我而言,我无法找出 2 个或更多端点的解决方案:

任何帮助将不胜感激。

这是我的 functions.php 代码:

function my_custom_endpoints() {
    add_rewrite_endpoint( 'my-server', EP_ROOT | EP_PAGES );
    add_rewrite_endpoint( 'my-affiliate', EP_ROOT | EP_PAGES ); 
}
add_action( 'init', 'my_custom_endpoints' );

function my_custom_query_vars( $vars ) {
    $vars[]= 'my-server';
    $vars[] = 'my-affiliate';
    return $vars;
}

add_filter( 'query_vars', 'my_custom_query_vars', 0 );

function my_custom_my_account_menu_items( $items ) {
    $items = array(
        'dashboard'         => __( 'Dashboard', 'woocommerce' ),
        'my-server'         => __( 'Servers', 'woocommerce' ),
        'orders'            => __( 'Orders', 'woocommerce' ),
        //'downloads'       => __( 'Downloads', 'woocommerce' ),
        //'edit-address'    => __( 'Addresses', 'woocommerce' ),
        //'payment-methods' => __( 'Payment Methods', 'woocommerce' ),
        'edit-account'      => __( 'Edit Accounts', 'woocommerce' ),
        'my-affiliate'      => __( 'Affiliate', 'woocommerce' ),
        'customer-logout'   => __( 'Logout', 'woocommerce' ),
    );

    return $items;
}

add_filter( 'woocommerce_account_menu_items', 'my_custom_my_account_menu_items' );


function my_affiliate_endpoint_content() {
    include 'woocommerce/myaccount/my-affiliate.php';   
}
add_action( 'woocommerce_account_my-affiliate_endpoint', 'my_affiliate_endpoint_content' );

function my_server_endpoint_content() {
    include 'woocommerce/myaccount/my-server.php';  
}
add_action( 'woocommerce_account_my-server_endpoint', 'my_server_endpoint_content' );

function my_custom_flush_rewrite_rules() {
    flush_rewrite_rules();
}
add_action( 'after_switch_theme', 'my_custom_flush_rewrite_rules' );

I am using Wordpress 4.5.3 with Woocommerce 2.6.2 on Theme Cardinal (Premium theme by Swiftideas).
I am running this website on WAMP / localhost.
I am not using any affiiliate plugins. I have created both the custom templates with some general HTML content. Affiliate Tab presently does not have any Affiliate related content only just html for me to use it once every thing is set.

参考文献:

重新保存您的永久链接。

任何时候出现 404重新保存永久链接 是一个安全的选择。它不会伤害并解决很多问题。据推测,您在切换主题后添加了第二个端点,因为一旦我在 woocommerce 文件夹中创建了一些假模板,您的代码对我来说工作正常。

Sidenote

Please don't put this kind of functionality in a theme.
It'd be better in a plugin and then you can flush the permalinks on activation/deactivation.