【问题标题】:Change "Billing Details" text to "Shipping Details" on WooCommerce checkout page在 WooCommerce 结帐页面上将“帐单详细信息”文本更改为“运输详细信息”
【发布时间】:2022-02-22 00:33:17
【问题描述】:

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

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

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+ 的代码 sn-p。

【问题讨论】:

    标签: php wordpress woocommerce translation checkout


    【解决方案1】:
    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 测试正常

    【讨论】:

    • 谢谢@MujeebuRahman!这很好用。除了格式化之外,我真的看不出这两个代码 sn-ps 之间有什么区别,但是你给我的那个效果很好。
    • @mujeebu-rahman 谢谢。您可以添加一个更改多个文本字段的示例吗?例如,还要删除“附加信息”标题?
    • 在一页结帐案例中也不能处理订阅产品
    【解决方案2】:

    要覆盖 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; ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-05
      • 1970-01-01
      相关资源
      最近更新 更多