我使用以下代码添加了一个自定义字段:
add_action( 'woocommerce_before_order_notes', 'bbloomer_add_custom_checkout_field' );
function bbloomer_add_custom_checkout_field( $checkout ) {
$current_user = wp_get_current_user();
$saved_gst_no = $current_user->gst_no;
woocommerce_form_field( 'gst_no', array(
'type' => 'text',
'class' => array( 'form-row-wide' ),
'label' => 'GST Number',
'placeholder' => 'GST Number',
'required' => true
//'default' => $saved_gst_no,
), $checkout->get_value( 'gst_no' ) );
}
在 GST 编号字段(自定义结帐字段)中输入任何值,然后通过单击“下订单”按钮进入付款屏幕并返回结帐页面而不完成交易,所有默认的 woocommerce 字段(如帐单电话、电子邮件等)都会自动填充会议。
但是,通过上述代码添加的自定义字段始终为空白。如何在访客用户的自定义字段中自动填充先前输入的值,类似于自动填充默认 woocommerce 字段的方式?