您要更改的文本位于checkout/form-checkout.php https://github.com/woocommerce/woocommerce/blob/1c4f02d2e2da598d202911acec0847fb26ae172a/templates/checkout/form-checkout.php line 54 https://github.com/woocommerce/woocommerce/blob/1c4f02d2e2da598d202911acec0847fb26ae172a/templates/checkout/form-checkout.php#L54
<h3 id="order_review_heading"><?php esc_html_e( 'Your order', 'woocommerce' ); ?></h3>
正如您将看到的,在之前和之后
-
woocommerce_checkout_before_order_review_heading
and
-
woocommerce_checkout_before_order_review
钩子,只有这些不适用于H3
tag
So gettext
如果您不想覆盖模板文件,建议使用此选项。
要调试此文本和其他文本,您可以使用
function filter_gettext( $translated, $text, $domain ) {
echo '<pre>', print_r( $text , 1 ), '</pre>';
return $translated;
}
add_filter( 'gettext', 'filter_gettext', 10, 3 );
所以要回答你的问题,这应该足够了
function filter_gettext( $translated, $text, $domain ) {
if( $text == 'Your order' && is_checkout() && ! is_wc_endpoint_url() ) {
// HERE set the desired specific product ID
$targeted_product_id = 1122;
// Loop through cart items
foreach( WC()->cart->get_cart() as $cart_item ) {
if( $targeted_product_id == $cart_item['data']->get_id() ) {
$translated = __( 'İletişim Bilgileri', $domain );
}
}
}
return $translated;
}
add_filter( 'gettext', 'filter_gettext', 10, 3 );
更新 10/2020
function filter_gettext( $translated, $text, $domain ) {
if( $text == 'Your order' && is_checkout() && ! is_wc_endpoint_url() ) {
// HERE set the desired specific product IDs
$targeted_product_ids = array( 1122, 30, 815 );
// Loop through cart items
foreach( WC()->cart->get_cart() as $cart_item ) {
// In array
if ( in_array( $cart_item['data']->get_id(), $targeted_product_ids ) ) {
$translated = __( 'İletişim Bilgileri', $domain );
}
}
}
return $translated;
}
add_filter( 'gettext', 'filter_gettext', 10, 3 );
function filter_gettext( $translated, $text, $domain ) {
if( $text == 'Your order' && is_checkout() && ! is_wc_endpoint_url() ) {
// Loop through cart items
foreach( WC()->cart->get_cart() as $cart_item ) {
// Is virtual
if ( $cart_item['data']->is_virtual() ) {
$translated = __( 'İletişim Bilgileri', $domain );
}
}
}
return $translated;
}
add_filter( 'gettext', 'filter_gettext', 10, 3 );