我想将结帐的结算字段的值预先填充到用户 before his first purchase 的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;
});
我在other post中读到了这个解决方案 . 占位符效果很好,但 Value 不大 .
此外,WooCommerce Doc(第1课)没有't say about anything the array value '默认'
1 回答
你're pretty close. This worked for me. I don'知道是否有必要,但我使用了一个命名函数,只有在用户存在时才获取
user_firstname
属性 .