【发布时间】:2018-08-24 16:21:03
【问题描述】:
我正在尝试更改/添加“已收到订单”Woocommerce 页面的标题。
以下 sn-p 有效 - 我可以使用以下代码更改预先存在的 TEXT:
add_filter('woocommerce_thankyou_order_received_text', 'woo_change_order_received_text', 10, 2 );
function woo_change_order_received_text( $str, $order ) {
$new_str = $str . ' We have emailed the purchase receipt to you.';
return $new_str;
}
下面的 sn-p 不起作用。 - 我无法更改/添加 TITLE 并传入用户名以对其进行个性化。这是我想要实现的输出的代码和图像......添加了 "You are awesome FIRSTNAME"。
<?php
add_filter( 'the_title', 'woo_personalize_order_received_title', 10, 2 );
function woo_personalize_order_received_title( $title, $id ) {
if ( is_order_received_page() && get_the_ID() === $id ) {
global $wp;
// Get the order. Line 9 to 17 are present in order_received() in includes/shortcodes/class-wc-shortcode-checkout.php file
$order_id = apply_filters( 'woocommerce_thankyou_order_id', absint( $wp->query_vars['order-received'] ) );
$order_key = apply_filters( 'woocommerce_thankyou_order_key', empty( $_GET['key'] ) ? '' : wc_clean( $_GET['key'] ) );
if ( $order_id > 0 ) {
$order = wc_get_order( $order_id );
if ( $order->get_order_key() != $order_key ) {
$order = false;
}
}
if ( isset ( $order ) ) {
//$title = sprintf( "You are awesome, %s!", esc_html( $order->billing_first_name ) ); // use this for WooCommerce versions older then v2.7
$title = sprintf( "You are awesome, %s!", esc_html( $order->get_billing_first_name() ) );
}
}
return $title;
}
这应该是可能的,因为有示例说明如何做到这一点,例如here...我只是想不通为什么主标题甚至不会出现?
【问题讨论】:
-
您的代码应该可以正常工作,实际上我只是在我的位置上对其进行测试,这很好,如果处于您的位置,我将首先开始提高优先级,如果它不起作用,请检查您的条件一一个
-
@kashalo - 例如(10,3)?...这很奇怪,因为文本的更改以与 (10,2) 相同的优先级工作
-
no (20, 2) 第一个参数是优先级第二个是您的过滤器应该有多少接受参数
-
这是不同的过滤器,因此不必为每个过滤器设置相同的优先级developer.wordpress.org/reference/functions/add_filter
-
@kashalo 我尝试将优先级调整为 (20,2),但仍然没有运气 - 真的很困惑为什么它不起作用
标签: php wordpress woocommerce checkout hook-woocommerce