Woocommerce(谢谢页面)在订单概览字段中添加自定义meta_key

时间:2020-09-12 10:24:21

标签: php wordpress woocommerce

在感谢页面加载https://ibb.co/ZKHDRb5时,我想显示电话号码而不是电子邮件。我已经为电话SMS网关安装了一个插件,并且它具有电话字段,因此我必须禁用计费电话,以便用户不会两次填充电话。在phpMyAdmin中,meta_key是“ digits_phone”。如何添加此元键来显示而不是显示电子邮件?我已经在子主题中复制了thankyou.php页面。

我尝试将billing_phone与digits_phone同步,也尝试了billing_postcode。

/* postcode and phone to copy the phone from digits_phone*/
$current_user_id = get_current_user_id();
$digits_phone = get_user_meta($current_user_id, 'digits_phone', true);

$metas = array( 
   // 'nickname'   => $userFirstName,
    'billing_postcode'  => $digits_phone,
    'billing_phone'     => $digits_phone, 
);

foreach($metas as $key => $value) {
    update_user_meta( $current_user_id, $key, $value );
}

在thankyou.php中,我尝试用get_billing_phone()和get_billing_postcode()替换“ get_billing_email()”。即使meta_kay在phpMyAdmin中也有数据,两者都什么也没显示。

<?php if ( is_user_logged_in() && $order->get_user_id() === get_current_user_id() && $order->get_billing_phone() ) : ?>
                    <li class="woocommerce-order-overview__email email">
                        <?php esc_html_e( 'Phone:', 'woocommerce' ); ?>
                        <strong><?php echo $order->get_billing_phone(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></strong>
                    </li>
                <?php endif; ?>

所以我想我只是使用meta_key“ digits_phone”,但我不知道如何编码它,而不是“ echo $ order-> get_billing_phone();”。如何在上面的代码中添加自定义meta_key?

1 个答案:

答案 0 :(得分:0)

我能够做到


        <li class="woocommerce-order-overview__email email">
                        <?php esc_html_e( 'Phone:', 'woocommerce' ); ?>
                        <strong><?php $user_id = get_current_user_id(); $current_phone = get_user_meta( $user_id, 'digits_phone', true); echo $current_phone;// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></strong>
                    </li>
相关问题