更改Woocommerce中特定产品的Checkout“Billing Details”文本

问题描述 投票:-2回答:2

如何仅针对特定产品更改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 );

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

php wordpress woocommerce checkout gettext
2个回答
2
投票

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

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 );
        }
    }
    return $translated;
}

代码位于活动子主题(或活动主题)的function.php文件中。经过测试和工作。

注意:在Woocommerce结帐中,要更改的文字是“结算明细”,“详情”中没有资金


0
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.