I am using Woocommerce version 2.4.12, the latest one. I want to make some changes to orders page that is in the admin dashboard under woocommerce --> orders.
Where is it's file in plugins->woocommerce folder? I have made a woocommerce folder in my theme to override template files. I want to add phone number of the customer to the ship_to column. Client wants Phone number of customer visible on the orders page. Any way to use functions.php to add a hook and make changes?
try this to your functions.php
add_filter( 'manage_edit-shop_order_columns', 'shop_order_columns' );
function shop_order_columns( $columns ){
$new_columns = (is_array($columns)) ? $columns : array();
$new_columns['phone'] = 'Phone';
return $new_columns;
}
add_action( 'manage_shop_order_posts_custom_column', 'shop_order_posts_custom_column' );
function shop_order_posts_custom_column( $column ){
global $post, $the_order;
if ( empty( $the_order ) || $the_order->get_id() != $post->ID ) {
$the_order = wc_get_order( $post->ID );
}
$billing_address = $the_order->get_address();
if ( $column == 'phone' ) {
echo ( isset( $billing_address['phone'] ) ? $billing_address['phone'] : '');
}
}
Position problem??..
try this for the first function
function shop_order_columns($columns){
$columns = (is_array($columns)) ? $columns : array();
$phone = array( 'phone' => 'Phone' );
$position = 5;
$new_columns = array_slice( $columns, 0, $position, true ) + $phone;
return array_merge( $new_columns, $columns );
}
Updated for WooCommerce 3.
You should use manage_shop_order_posts_custom_column
action and change the column data by checking the column name
switch( $column ) {
case 'shipping_address' :
echo 'sample data';
break;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With