在 WooCommerce 结账页面上将 "Billing Details" 文本更改为 "Shipping Details"

Change "Billing Details" text to "Shipping Details" on WooCommerce checkout page

我目前在我的子主题的 functions.php 文件中有一些代码,应该在我的 WooCommerce 结帐页面上将“账单明细”更改为“运输明细”。

但是,当我更新到 WooCommerce 3.0 时,代码片段停止工作。下面是我使用的代码。

function wc_billing_field_strings( $translated_text, $text, $domain ) {
    switch ( $translated_text ) {
        case 'Billing Details' :
            $translated_text = __( 'Shipping Details', 'woocommerce' );
            break;
    }
    return $translated_text;
}

add_filter( 'gettext', 'wc_billing_field_strings', 20, 3 );

我非常想要一个适用于 WooCommerce 3.0+ 的代码片段。

function wc_billing_field_strings( $translated_text, $text, $domain ) {
    switch ( $translated_text ) {
        case 'Billing details' :
            $translated_text = __( 'Billing Info', 'woocommerce' );
            break;
    }
    return $translated_text;
}
add_filter( 'gettext', 'wc_billing_field_strings', 20, 3 );

使用 WooCommerce 3.0.6 测试正常

要覆盖 woocommerce 视图,您需要将所需的模板文件从 woocommerce/templates 复制到您的主题目录。在这种情况下,将 woocommerce/templates/checkout/form_billing.php 作为 woocommerce/checkout/form_billing.php 复制到您的主题文件夹,并在第 27 行附近编辑以下代码。

<?php if ( wc_ship_to_billing_address_only() && WC()->cart->needs_shipping() ) : ?>

    <h3><?php _e( 'Billing &amp; Shipping', 'woocommerce' ); ?></h3>

<?php else : ?>

    <h3><?php _e( 'Billing details', 'woocommerce' ); ?></h3>

<?php endif; ?>