且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

wordpress woocommerce - 在结帐页面上显示和修改帐户字段

更新时间:2023-11-30 14:52:04

我已经找到了答案,所以如果有人遇到同样的问题,这是***的解决方案.与尝试使帐户字段可见,在我的情况下,手动输出我需要的字段更有效,因为无论如何我都不需要大多数默认字段.

I've found the answer to this, so if anyone has the same problem, this is the best solution. Instead of trying to make the accounts fields visible, in my case it's more efficient to manually output the fields I need since I won't be needing most of the default fields anyway.

我所做的是覆盖了form-b​​illing.php 模板.我删除了这部分字段的循环:

What I did was override the form-billing.php template. I removed the loop for the fields which is this part:

<?php foreach ( $checkout->checkout_fields['billing'] as $key => $field ) : ?>

    <?php woocommerce_form_field( $key, $field, $checkout->get_value( $key ) ); ?>

<?php endforeach; ?>

并将其替换为将它们单独添加到页面中:

And replaced it with this to individually add them to the page:

<?php
    woocommerce_form_field( 'billing_first_name', $checkout->checkout_fields['billing']['billing_first_name'], $checkout->get_value( 'billing_first_name') );
    woocommerce_form_field( 'billing_email', $checkout->checkout_fields['billing']['billing_email'], $checkout->get_value( 'billing_email') );
    woocommerce_form_field( 'account_username', $checkout->checkout_fields['account']['account_username'], $checkout->get_value( 'account_username') );
    woocommerce_form_field( 'account_password', $checkout->checkout_fields['account']['account_password'], $checkout->get_value( 'account_password') );
    woocommerce_form_field( 'account_password-2', $checkout->checkout_fields['account']['account_password-2'], $checkout->get_value( 'account_password-2') );
    //...other fields that I need
?>

从那里开始,对标签、占位符等的修改工作正常.希望它也适用于其他有同样问题的人.干杯!:)

From there, the modifications for the label, placeholder, etc. works just fine. Hope it works for other people with the same issues too. Cheers! :)