admin管理员组文章数量:1122846
I'm a little new to Wordpress/Woocommerce but am fumbling my way through...
We have Woocommerce installed and working where we request billing address and billing phone number (amongst other things) and I am trying to show this data on the backend users (view all) table as it currently only pulls its data from the base Wordpress registrations details, not from Woocommerce.
Any help would be greatly appreciated.
Update: This is where I am hoping to add some extra columns using Woocommerce details.
I'm a little new to Wordpress/Woocommerce but am fumbling my way through...
We have Woocommerce installed and working where we request billing address and billing phone number (amongst other things) and I am trying to show this data on the backend users (view all) table as it currently only pulls its data from the base Wordpress registrations details, not from Woocommerce.
Any help would be greatly appreciated.
Update: This is where I am hoping to add some extra columns using Woocommerce details.
Share Improve this question edited Apr 19, 2017 at 6:58 mobius2000 asked Apr 19, 2017 at 3:02 mobius2000mobius2000 112 bronze badges 5- hello can you include a screenshot of where you like the info to show on wordpress backend just so i can be clear of your question. – frenchy black Commented Apr 19, 2017 at 5:56
- Hi there, updated original post. – mobius2000 Commented Apr 19, 2017 at 6:59
- You could just use the answer given in the post that you took that screenshot away from. wordpress.stackexchange.com/questions/160422/… Otherwise look at the Admin Columns plugin – Jebble Commented Apr 19, 2017 at 7:47
- Possible duplicate of Add custom column to Users admin panel – Jebble Commented Apr 19, 2017 at 7:51
- I agree it's close to a duplicate however isn't that response using the content from the first step of the solution? The first step adds the form to the registration page of a standard wordpress install. My understanding is this content is already there as it's built into the Woocommerce billing form so what I am asking is how do I get data from that form? Step two of that solution pulls data from the newly created form content. – mobius2000 Commented Apr 19, 2017 at 9:25
1 Answer
Reset to default 0All the code below is for your current theme functios.php
file (but better use a child theme or a custom plugin).
Step 1.
Not sure if you figured out with adding the columns, but I will mention it too - use manage_users_columns
hook.
add_filter( 'manage_users_columns', 'new_modify_user_table' );
function new_modify_user_table( $columnnames ) {
return array_slice( $columnnames, 0, 3, true )
+ array( 'billing_address' => 'Billing Address' )
+ array_slice( $columnnames, 3, NULL, true );
}
array_slice()
function is required because we're adding the column on the 3rd place in the table.
Step 2.
It is time to use manage_users_custom_column
hook to add the data to the column. So, we're adding billing address and phone.
add_filter( 'manage_users_custom_column', 'new_modify_user_table_row', 10, 3 );
function new_modify_user_table_row( $val, $column_name, $user_id ) {
switch ($column_name) {
case 'billing_address' :
$val = get_user_meta( $user_id, 'billing_address_1', true ) . '<br />';
$val .= get_user_meta( $user_id, 'billing_phone', true );
break;
}
return $val;
}
If you're looking for how to get the complete billing address information (state, country etc), look at this code example.
本文标签: Backend users listadd Woocommerce meta to table
版权声明:本文标题:Backend users list - add Woocommerce meta to table 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736288968a1928205.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论