如何在 Woocommerce 我的帐户侧边栏中添加新的自定义标题?

How to add new Custom Title in Woocommerce My Account sidebar?

您好,我想在我的 WooCommerce 网站的“我的帐户”页面中添加新的自定义标题和链接。搜索了所有文档和 Whosebug 主题,但没有找到符合我要求的解决方案。

这是我要求的标题

英文文本 Muj Ucet 是我的帐户。 :)

我想添加新标题,如下图所示:

这是该部分的 WooCommerce 模板代码:

<?php


if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
?>

<p><?php
/* translators: 1: user display name 2: logout url */
printf(
    __( 'Hello %1$s (not %1$s? <a href="%2$s">Log out</a>)', 'woocommerce' 
 ),
    '<strong>' . esc_html( $current_user->display_name ) . '</strong>',
    esc_url( wc_logout_url( wc_get_page_permalink( 'myaccount' ) ) )
);
?></p>

<p>Na nástěnce svého uživatelského účtu si můžete stáhnout své zakoupené 
produkty a faktury, upravit své osobní informace, změnit heslo nebo 
fakturační adresu.</p>

<?php
/**
 * My Account dashboard.
 *
 * @since 2.6.0
 */
do_action( 'woocommerce_account_dashboard' );

/**
 * Deprecated woocommerce_before_my_account action.
 *
 * @deprecated 2.6.0
 */
do_action( 'woocommerce_before_my_account' );


/**
 * Deprecated woocommerce_after_my_account action.
 *
 * @deprecated 2.6.0
 */
do_action( 'woocommerce_after_my_account' );

/* Omit closing PHP tag at the end of PHP files to avoid "headers already 
sent" issues. */

我想在该侧边栏下方添加一个新标题。如何注册一个新标题?

谢谢

这是解决方案。

add_filter('woocommerce_account_menu_items', 'display_account_new_link');
function display_account_new_link( $items ) {
    $items['new_link'] = __( 'New Link', 'text-domain' );
    return $items;
}
add_action( 'woocommerce_account_new_link_endpoint', 'new_account_link_content' );
function new_account_link_content() {
    //include your display template here
    echo "Here goes you content";
}

将此代码粘贴到您的插件或主题 function.php 文件后,此代码将在我的帐户导航侧边栏中创建一个新的 link,以及您要分配此 link。这里 new_link 是此导航 link 的 slug。如果你想给出一些不同的 slug,你必须重命名给定代码中各处的 new_link。只要您单击此新建 Link,它就会将您重定向到“未找到页面”页面。加入这段代码即可解决

add_action( 'init', 'register_new_link_endpoint');
function register_new_link_endpoint() {
    add_rewrite_endpoint( 'new_link', EP_PAGES );
}

粘贴此代码后,您必须保存 permalink 一次,方法是转到 WordPress 仪表板->设置->Permalinks 并点击保存更改按钮。