Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WP - WOO | Add custom field to shop_order Woocommerce Admin Order's List + Search #Wordpress #Woocommerce
<?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