Last active
April 19, 2019 18:07
-
-
Save amouratoglou/f7749525ee41a5e9a529b3871e698ef0 to your computer and use it in GitHub Desktop.
WP - WOO | Add custom field to shop_order Woocommerce Admin Order's List + Search #Wordpress #Woocommerce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* | |
* Add a new Column to shop_order | |
* admin list Woocommerce and show custom fields | |
* add support to search custom field | |
* | |
* Use in functions.php | |
*/ | |
add_action( 'shop_order_manage_custom_column' , 'custom_order_list_column_content', 10, 2 ); | |
function custom_order_list_column_content( $column, $post_id ) | |
{ | |
// HERE get the data from your custom field (set the correct meta key below) | |
$add_new_column_to_woocommerce = get_post_meta( $post_id, 'replace_with_custom_field', true ); | |
if( empty($add_new_column_to_woocommerce)) $add_new_column_to_woocommerce = ''; | |
switch ( $column ) | |
{ | |
case 'order_add_new_column_to_woocommerce' : | |
echo '<span>'.$add_new_column_to_woocommerce.'</span>'; // display the data | |
break; | |
} | |
} | |
// MAKE 'add_new_column_to_woocommerce' METAKEY SEARCHABLE IN THE SHOP ORDERS LIST | |
// replace with your custom field | |
add_filter( 'woocommerce_shop_order_search_fields', 'add_new_column_to_woocommerce_search_fields', 10, 1 ); | |
function add_new_column_to_woocommerce_search_fields( $meta_keys ){ | |
$meta_keys[] = 'replace_with_custom_field'; | |
return $meta_keys; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment