WooCommerce-在“我的帐户"页面中将端点分配给多个自定义模板 [英] WooCommerce - Assign endpoints to multiple custom templates in my-account page

查看:231
本文介绍了WooCommerce-在“我的帐户"页面中将端点分配给多个自定义模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to add 2 endpoints and associate them with two custom templates. 'my-server' -> 'Servers' and 'my-affiliate -> 'Affiliate'.

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

I also have created two custom templates:

  • my-server.php
  • my-affiliate.php

它们两个都位于我的theme > woocommerce > myaccount文件夹中.关联企业页面正确指向 url/myaccount/my-affiliate .

Both of them are located in my theme > woocommerce > myaccount folder. Affiliate page is pointing correctly to url/myaccount/my-affiliate.

但是我的问题是服务器给出了找不到404页"错误.

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

我尝试在此线程中使用该解决方案:
DarioFerrer 的分辨率非常适合单个端点和单个自定义模板.

I have tried to use the solution in this thread:
Assigning an endpoint to a custom template in my account pages
Ideally I should have requested this as an comment but I do not have sufficient reputation to comment. DarioFerrer 's resolution works great for a single endpoint and a single custom template.

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

In my case, I cannot figure out the solution for 2 or more endpoints:

  • 如何包括两个以上的端点?
  • 如何将它们各自分配给自定义模板?

任何帮助将不胜感激.

这是我的functions.php代码:

This is my functions.php code:

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' );

我在主题主教(Swiftideas的Premium主题)上使用了带有Woocommerce 2.6.2的Wordpress 4.5.3.
我正在WAMP/localhost上运行此网站.
我没有使用任何附属插件.我已经创建了带有一些常规HTML内容的两个自定义模板. Affiliate Tab目前没有任何与Affiliate相关的内容,只有html可供我在设置所有内容后使用.

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.

参考:

  • Assigning an endpoint to a custom template in my account pages
  • Tabbed My Account page (Woocommerce 2.6+): Creating new endpoints

推荐答案

重新保存您的永久链接.

每当您有404个时,重新保存永久链接是一个安全的选择.它不会伤害并解决很多问题.大概是在切换主题之后添加了第二个端点,因为一旦我在woocommerce文件夹中创建了一些假模板,您的代码就可以正常工作.

Any time you have 404s, It's a safe bet to re-save your permalinks. It can't hurt and solves a lot of problems. Presumably, you added the 2nd endpoint after switching themes because once I created some fake templates in the woocommerce folder, your code worked fine for me.

边注

请不要在主题中加入这种功能.
最好使用插件,然后在激活/停用时刷新永久链接.

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.

这篇关于WooCommerce-在“我的帐户"页面中将端点分配给多个自定义模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆