第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

在某些條件下,如何更改 WooCommerce 結(jié)賬頁面上的“您的訂單”文本

在某些條件下,如何更改 WooCommerce 結(jié)賬頁面上的“您的訂單”文本

PHP
慕田峪4524236 2023-09-08 14:13:18
使用此代碼,我可以更改結(jié)帳頁面中的“您的訂單”文本。但我需要更改我的購(gòu)物車中的特定產(chǎn)品或虛擬產(chǎn)品是否在我的購(gòu)物車中。function custom_wc_translations($translated){    $text = array(    'Your order' => 'Your new phrase',    'any other string' => 'New string',    );    $translated = str_ireplace(  array_keys($text),  $text,  $translated );    return $translated;}add_filter( 'gettext', 'custom_wc_translations', 20 );我找到了此代碼,但針對(duì)特定產(chǎn)品的不同位置。我怎樣才能改變它?add_filter(  'gettext',  'change_conditionally_order_review_heading_text', 10, 3 );function change_conditionally_order_review_heading_text( $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() )                return __( '?leti?im Bilgileri', $domain );        }    }    return $translated;}
查看完整描述

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 );


查看完整回答
反對(duì) 回復(fù) 2023-09-08
  • 1 回答
  • 0 關(guān)注
  • 112 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)