我想在用户的第一次购买之前将结账字段的值预先填充到用户的DB存储值中。
我尝试了以下代码:
add_filter( 'woocommerce_checkout_fields' , function ( $fields ) {
$fields['billing']['billing_first_name']['placeholder'] = 'First Name';
$fields['billing']['billing_first_name']['default'] = wp_get_current_user()->user_firstname;
return $fields;
});我在其他员额中读到过这个解决方案。占位符工作得很好,但它的值却没有。
此外,WooCommerce医生 (第1课)没有提到数组值‘默认’的任何内容
发布于 2016-10-08 13:50:26
你们关系很好。这对我有用。我不知道是否有必要,但我使用了一个命名函数,并且只有当用户存在时才获得user_firstname属性。
add_filter( 'woocommerce_checkout_fields' , 'kia_checkout_field_defaults', 20 );
function kia_checkout_field_defaults( $fields ) {
$user = wp_get_current_user();
$first_name = $user ? $user->user_firstname : '';
$fields['billing']['billing_first_name']['placeholder'] = 'First Name';
$fields['billing']['billing_first_name']['default'] = $first_name;
return $fields;
}https://stackoverflow.com/questions/39922747
复制相似问题