我已使用以下代碼將標題添加到帳戶的所有頁面:
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 更改了查看訂單頁面的 url:
在 WooCommerce 我的帳戶中將“view-order/order-id”url/endpoint 更改為“orders/order-id”
Title更改前url view-order page : order # (order-id)
更改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 );
uj5u.com熱心網友回復:
通過您所做的更改,您還更改了端點。為了使該特定更改順利運行,您必須:
代替:
<?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>' );
?>
相關:在 WooCommerce 我的帳戶中將“view-order/order-id”網址/端點更改為“orders/order-id”
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/482027.html
標籤:php WordPress woocommerce 端点 订单