简体   繁体   English

在 WooCommerce 我的帐户中更改标题自定义“查看订单”端点

[英]Change title custom "view-order" endpoint in WooCommerce My account

I have added the title to all the pages of the account using the following code:我已使用以下代码将标题添加到帐户的所有页面:

add_filter( 'the_title', 'wc_page_endpoint_title' );
the_title( '<h2>', '</h2>' );

Path: plugins/woocommerce/templates/myaccount/my-account.php路径: plugins/woocommerce/templates/myaccount/my-account.php

<?php
/**
 * My Account page
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/myaccount/my-account.php.
 *
 * HOWEVER, on occasion WooCommerce will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
 * @see     https://docs.woocommerce.com/document/template-structure/
 * @package WooCommerce\Templates
 * @version 3.5.0
 */

defined( 'ABSPATH' ) || exit;

/**
 * My Account navigation.
 *
 * @since 2.6.0
 */
do_action( 'woocommerce_account_navigation' ); ?>

<div class="woocommerce-MyAccount-content">
    <?php
        add_filter( 'the_title', 'wc_page_endpoint_title' );
        the_title( '<h2>', '</h2>' );
    ?>
    <?php
        /**
         * My Account content.
         *
         * @since 2.6.0
         */
        do_action( 'woocommerce_account_content' );
    ?>
</div>

I also changed the url of the view-order page using the following url :我还使用以下 url 更改了查看订单页面的 url:

Change "view-order/order-id" url/endpoint in WooCommerce My account - orders to "orders/order-id" 在 WooCommerce 我的帐户中将“view-order/order-id”url/endpoint 更改为“orders/order-id”

  • Title Before the change url view-order page : order # (order-id) Title 更改url view-order page : order # (order-id)

  • Title after the change url view-order page : orders更改url的标题查看订单页面:orders

I want it to be the same as before我希望它和以前一样

The following code does not work either:以下代码也不起作用:

function filter_woocommerce_endpoint_view_order_title( $title, $endpoint, $action ) {
   $title = __( 'test', 'woocommerce' );
   return $title;
}
add_filter( 'woocommerce_endpoint_view-order_title', 'filter_woocommerce_endpoint_view_order_title', 10, 3 );

With the changes you made, you also changed the endpoint.通过您所做的更改,您还更改了端点。 To make this run smoothly for that specific change, you must:为了使该特定更改顺利运行,您必须:

Replace:代替:

<?php
    add_filter( 'the_title', 'wc_page_endpoint_title' );
    the_title( '<h2>', '</h2>' );
?>

With:和:

<?php
    function filter_the_title( $title, $id ) {
        global $wp;

        if ( isset( $wp->query_vars['orders'] ) && is_numeric( $wp->query_vars['orders'] ) ) {
            $order = wc_get_order( $wp->query_vars['orders'] );
            /* translators: %s: order number */
            $title = ( $order ) ? sprintf( __( 'Order #%s', 'woocommerce' ), $order->get_order_number() ) : '';
        } else {
            $title = wc_page_endpoint_title( $title );
        }

        return $title;
    }
    add_filter( 'the_title', 'filter_the_title', 10, 2 );
    the_title( '<h2>', '</h2>' );
?>

Related: Change "view-order/order-id" url/endpoint in WooCommerce My account - orders to "orders/order-id"相关:在 WooCommerce 我的帐户中将“view-order/order-id”网址/端点更改为“orders/order-id”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM