-1

如何仅为特定产品更改 Woocommerce 结帐页面中的文本“帐单详细信息”?

我努力了:

/* Change the Billing Details checkout label to Your Details: */
function wc_billing_field_strings( $translated_text, $text, $domain ) 
{
switch ( $translated_text ) {
case 'Billing Details' :
$translated_text = __( 'Your Details', 'woocommerce' );
break;
}
return $translated_text;
}
add_filter( 'gettext', 'wc_billing_field_strings', 20, 3 );

但它正在改变所有产品的文本……我怎么能为一种特定的产品做到这一点?

4

2 回答 2

4

要在购物车中有特定商品时更改结帐页面中的可翻译文本,请使用以下命令:

add_filter(  'gettext',  'change_conditionally_checkout_heading_text', 10, 3 );
function change_conditionally_checkout_heading_text( $translated, $text, $domain  ) {
    if( $text === 'Billing details' && is_checkout() && ! is_wc_endpoint_url() ){
        // HERE set the desired specific product ID
        $targeted_product_id = 1980;

        // Loop through cart items
        foreach( WC()->cart->get_cart() as $cart_item ) {
            if( $targeted_product_id == $cart_item['data']->get_id() ) {
                return __( 'Your Details', $domain );
                break; // Stop the loop
            }
        }
    }
    return $translated;
}

代码在您的活动子主题(或活动主题)的functions.php 文件中。测试和工作。

注意:在Woocommerce结帐中,要更改的文本是“账单详细信息”,“详细信息”中没有大写字母

于 2019-03-28T22:50:50.823 回答
-1

首先,覆盖 Woocommerce 插件模板并在其中更改 wp-content/plugins/woocommerce/templates/checkout/form-checkout.php

找到您需要的模板并更改文本。

于 2019-03-28T07:25:56.793 回答