php – WooCommerce |设置结算字段值
发布时间:2020-12-13 17:01:35 所属栏目:PHP教程 来源:网络整理
导读:我想在首次购买之前将结帐的结算字段的值预填充到用户的DB存储值. 我试过以下代码: add_filter( 'woocommerce_checkout_fields',function ( $fields ) { $fields['billing']['billing_first_name']['placeholder'] = 'First Name'; $fields['billing']['bil
我想在首次购买之前将结帐的结算字段的值预填充到用户的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中读到了这个解决方案.占位符效果很好,但价值却没有. 此外,WooCommerce Doc(第1课)没有说任何数组值’默认’ 解决方法
你很亲密.这对我有用.我不知道是否有必要,但我使用了一个命名函数,只有用户存在时才获取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; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |