1 回答

TA貢獻(xiàn)1875條經(jīng)驗(yàn) 獲得超3個(gè)贊
您要更改的文本位于第54checkout/form-checkout.php
行
<h3?id="order_review_heading"><?php?esc_html_e(?'Your?order',?'woocommerce'?);??></h3>
正如您將看到的,在之前和之后
woocommerce_checkout_before_order_review_heading
和woocommerce_checkout_before_order_review
鉤子,只有這些不適用于H3
標(biāo)簽
gettext
如果您不想覆蓋模板文件,建議您這樣做。
要調(diào)試此文本和其他文本,您可以使用
function filter_gettext( $translated, $text, $domain? ) {
? ? echo '<pre>', print_r( $text , 1 ), '</pre>';
? ? return $translated;
}
add_filter( 'gettext',? 'filter_gettext', 10, 3 );
所以要回答你的問題,這應(yīng)該足夠了
檢查特定產(chǎn)品 ID
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
您可以使用以下代碼來檢查多個(gè)產(chǎn)品ID
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 );
要檢查您可以使用的虛擬產(chǎn)品
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 );
- 1 回答
- 0 關(guān)注
- 112 瀏覽
添加回答
舉報(bào)