如果没有输入单独的送货地址,如何有条件地更改WooCommerce帐单地址标题 [英] How to conditionally change WooCommerce billing address title if no separate shipping address is entered

查看:54
本文介绍了如果没有输入单独的送货地址,如何有条件地更改WooCommerce帐单地址标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站有两个选择

  • 您可以运送到帐单地址
  • 您可以输入帐单地址和单独的收货地址,非常标准.

如果在结帐时同时输入帐单地址和送货地址,则在我的帐户"的订单详细信息页面中,您可以在相关地址上方看到帐单地址和送货地址标题.

If you enter both a billing and a shipping address during checkout, then in the order details page in My Account you can see both Billing address and Shipping address titles above the relevant addresses.

如果仅在结帐时输入帐单邮寄地址,则在我的帐户"中的订单详细信息页面中,您只能看到帐单邮寄"地址,该地址不会与送货地址重复.没有显示送货地址,所以看起来很奇怪.

If you only enter a billing address during checkout, in the order details page in My Account you can only see 'Billing' address, the address isn't duplicated as the shipping address. No Shipping address is shown, so it looks strange.

我想有条件地将结算地址"重命名为结算&送货地址"(如果订单没有单独的送货地址.

I would like to conditionally rename 'Billing address' to 'Billing & Shipping address' if the order has no separate shipping address.

在电子邮件中进行更改也将是有益的,因为这样做更有意义.

It would be beneficial to change it in the emails as well, as it would make more sense.

我发现这是为了重命名标题(我尚未测试过),但是如何有条件地做到这一点?

I have found this for renaming the title (I haven't tested it), but how can I do it conditionally?

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

    return $translated_text;
}
add_filter( 'gettext', 'wc_billing_field_strings', 20, 3 );

推荐答案

我的帐户

https://github.com /woocommerce/woocommerce/blob/master/templates/order/order-details-customer.php

  • 可以将该模板复制到yourtheme/woocommerce/order/order-details-customer.php中,以覆盖该模板.

替换(行: 31 )

<h2 class="woocommerce-column__title"><?php esc_html_e( 'Billing address', 'woocommerce' ); ?></h2>

使用

<h2 class="woocommerce-column__title">
<?php
// Show shipping = false    
if ( !$show_shipping ) {
    $title = 'Billing & Shipping address';      
} else {
    $title = 'Billing address';
}

esc_html_e( $title, 'woocommerce' );
?>
</h2>


电子邮件

https://github.com/woocommerce /woocommerce/blob/master/templates/emails/email-addresses.php

  • 可以将该模板复制到yourtheme/woocommerce/emails/email-addresses.php中,以覆盖该模板.

替换(行: 29 )

<h2><?php esc_html_e( 'Billing address', 'woocommerce' ); ?></h2>

使用

<h2>
<?php 
// Billing_address
if ( !$order->needs_shipping_address() ) {
    $title = 'Billing & Shipping address';     
} else {
    $title = 'Billing address';
}

esc_html_e( $title, 'woocommerce' );
?>
</h2>

这篇关于如果没有输入单独的送货地址,如何有条件地更改WooCommerce帐单地址标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆