在 WooCommerce 我的帐户中更改标题自定义 "view-order" 端点
Change title custom "view-order" endpoint in WooCommerce My account
我已使用以下代码将标题添加到帐户的所有页面:
add_filter( 'the_title', 'wc_page_endpoint_title' );
the_title( '<h2>', '</h2>' );
路径: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>
我还使用以下 url 更改了 view-order 页面的 url :
标题更改前urlview-order页面:顺序#(order-id)
标题 更改后 url view-order 页面:订单
我希望它和之前
一样
以下代码也不起作用:
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>' );
?>
相关:
我已使用以下代码将标题添加到帐户的所有页面:
add_filter( 'the_title', 'wc_page_endpoint_title' );
the_title( '<h2>', '</h2>' );
路径: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>
我还使用以下 url 更改了 view-order 页面的 url :
标题更改前urlview-order页面:顺序#(order-id)
标题 更改后 url view-order 页面:订单
我希望它和之前
一样以下代码也不起作用:
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>' );
?>
相关: