为了账号安全,请及时绑定邮箱和手机立即绑定

在 WooCommerce 上向格式化的计费电话和电子邮件添加标签,谢谢

在 WooCommerce 上向格式化的计费电话和电子邮件添加标签,谢谢

PHP
慕丝7291255 2023-06-24 17:56:37
我想在“谢谢”页面上的电话和电子邮件信息中添加自定义标签。使用 YITH WooCommerce Checkout Manager,我自定义了一些字段并将以下代码添加到functions.php:function woo_custom_order_formatted_billing_address( $address , $WC_Order ) {$address = array(            'first_name' => 'First Name: ' . $WC_Order->billing_first_name,            'address_1'  => 'Address: ' . $WC_Order->billing_address_1,            'city'      => 'City: ' . $WC_Order->billing_city,        );        if(!empty($ship_date)) $address['order_time'] = 'Shipping time: ' . $ship_date;        if(!empty($WC_Order->billing_corpus)) $address['house'] = 'House: ' . $WC_Order->billing_house;        if(!empty($WC_Order->billing_corpus)) $address['corpus'] = 'Corpus: ' . $WC_Order->billing_corpus;        if(!empty($WC_Order->billing_flat)) $address['flat'] = 'Room: ' . $WC_Order->billing_flat;            if(!empty($WC_Order->billing_phone)) $address['billing_phone'] = 'Phone: ' . $WC_Order->billing_phone;        return $address;}但由于某种原因,不想添加标签“电话”。有什么解决办法吗?
查看完整描述

1 回答

?
慕慕森

TA贡献1856条经验 获得超17个赞

为此,您可以使用两种不同的方式来做到这一点:

1)。通过您的主题覆盖 WooCommerce 模板

您必须复制/编辑order/order-details-customer.php模板文件,因为帐单格式地址功能不处理帐单电话和帐单电子邮件。

对于计费电话,您需要更换线路37

<p class="woocommerce-customer-details--phone"><?php echo esc_html( $order->get_billing_phone() ); ?></p>

通过以下行:

<p class="woocommerce-customer-details--phone"><?php _e("Phone: ", "woocommerce"); echo esc_html( $order->get_billing_phone() ); ?></p>

对于帐单电子邮件,您需要替换该行41

<p class="woocommerce-customer-details--email"><?php echo esc_html( $order->get_billing_email() ); ?></p>

通过以下行:

<p class="woocommerce-customer-details--email"><?php _e("Email: ", "woocommerce"); echo esc_html( $order->get_billing_email() ); ?></p>

2)。使用一些复合过滤器挂钩 (用于已收到的订单 - 感谢页面)

// Phone

add_filter('woocommerce_order_get_billing_phone', 'wc_order_get_billing_phone_filter' );

function wc_order_get_billing_phone_filter( $billing_phone ) {

    // Only on Order Received page (thankyou)

    if ( is_wc_endpoint_url( 'order-received' ) && $billing_phone ) {

        return __("Phone:", "woocommerce") . ' ' . $billing_phone;

    }

    return $billing_phone;

}


// Email

add_filter('woocommerce_order_get_billing_email', 'wc_order_get_billing_email_filter' );

function wc_order_get_billing_email_filter( $billing_email ) {

    // Only on Order Received page (thankyou)

    if ( is_wc_endpoint_url( 'order-received' ) && $billing_email ) {

        return __("Email:", "woocommerce") . ' ' . $billing_email;

    }

    return $billing_email;

}

代码位于活动子主题(或活动主题)的functions.php 文件中。经过测试并有效。


查看完整回答
反对 回复 2023-06-24
  • 1 回答
  • 0 关注
  • 107 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号