在WooCommerce中更改标题自定义"view-order"端点 我的帐户



我已使用以下代码将标题添加到帐户的所有页面:

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

路径:plugins/woocommerce/模板/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 WooCommerceTemplates
* @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>

我还使用以下url更改了查看顺序页面的url:

改变"查看订单/order-id"我的帐户-订单到"orders/order-id"

标题
  • 修改url查看订单页面:order # (order-id)

  • <
  • 标题strong>在更改url查看订单页面:orders

我希望它与之前的相同

下面的代码也不起作用:

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

您所做的更改还更改了端点。要使此程序在特定更改时顺利运行,您必须:

替换:

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

:

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

相关:Change "view-order/order-id"我的帐户-订单到"orders/order-id"

最新更新