无法将自定义页面/选项卡添加到我的帐户WooCommerce

时间:2018-06-07 作者:NRav

我已经试了一遍又一遍,但都是空手而归。我已经学习了本教程(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’;
提前感谢:)

2 个回复
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();

SO网友:nmr

在代码中,您没有向查询变量添加端点。

缺少代码:

function custom_query_vars( $vars ) {
    $vars[] = \'earnings\';
    return $vars;
}
add_filter( \'query_vars\', \'custom_query_vars\', 0 );

结束

相关推荐

Making sub-menus exclusive

我真的不知道该怎么解释我在这里找的东西,我在这里找得太露骨了。在我的网站上,我有一个附带菜单,其中包含一系列子类别,每个子类别中都有一些项目。我想知道当我打开另一个子类别时,是否有办法关闭所有其他打开的子类别,例如:1. Animals ----A. Cats ----B. Dogs 2. People ----A. Samantha ----B. Daniel 当我按下“动物”时,我希望“人”关闭,反之亦