Home › Forums › WooCommerce Personalized Product Options Manager (PPOM) › Create sortable Column in Woocommerce Orders page using PPOM meta field(s)
- This topic has 2 replies, 3 voices, and was last updated 5 years, 8 months ago by Jane Brian.
-
AuthorPosts
-
September 11, 2018 at 4:31 am #9362BrianParticipant
I’m using PPOM to take inputs from the customer as part of their order. A few of these fields include a date, and two text input fields. If possible, I’d like to be able to display these customer inputs as a sortable column in the Admin Orders Page once the customer places their order. This would allow for sorting/collecting orders based on meta field inputs across multiple orders.
I’m seeing if I can implement the sortable columns using the following tutorial: https://rudrastyh.com/woocommerce/columns.html#purchased_products_column
I’m unclear what the PPOM meta field variable names are if I implement this using a php addition to the functions.php file, is it the “Data name” field with a prefix or suffix? Is it possible to have conflicts in the “Data name” across multiple meta groups?
Below is some experimental code I have right now which would be added to the functions.php file to create a sortable ‘Birthday’ column, but it is not correctly populating the column possibly because I’m not using the correct meta variable names (the PPOM field name is “birthday”, meta group 1).
Any help is appreciated.
Example Code:
// add new column add_filter( 'manage_edit-shop_order_columns', 'column_birthday', 20 ); // populate new column add_action( 'manage_shop_order_posts_custom_column', 'populate_birthday' ); // make column sortable add_filter('manage_edit-shop_order_sortable_columns', 'sort_birthday'); // how to sort add_action( 'pre_get_posts', 'sort_birthday_column' ); function column_birthday( $order_columns ) { // a little different way of adding new columns return wp_parse_args( array( 'birthday' => 'Birthday' ), $order_columns ); } function populate_birthday( $column_id ) { if( $column_id == 'birthday' ) echo get_post_meta( get_the_ID(), 'birthday', true ); } function sort_birthday( $a ){ return wp_parse_args( array( 'birthday' => 'by_birthday' ), $a ); } function sort_birthday_column( $query ) { if( !is_admin() || empty( $_GET['orderby']) || empty( $_GET['order'] ) ) return; if( $_GET['orderby'] == 'by_birthday' ) { $query->set('meta_key', 'birthday' ); $query->set('orderby', 'meta_value_date'); $query->set('order', $_GET['order'] ); } return $query; }
September 11, 2018 at 2:48 pm #9365nmediaKeymasterHi,
well it has nothing to with meta groups all meta are saved with order order (update_order_meta) with data_name as key. So your code seems find as long as you are using correct key (data_name) for birthday field.
April 28, 2019 at 4:19 pm #11960Jane BrianKeymasterHI
It has been a long while for this topic, so we are closing this. -
AuthorPosts
- The topic ‘Create sortable Column in Woocommerce Orders page using PPOM meta field(s)’ is closed to new replies.