After reading https://rudrastyh.com/woocommerce/columns.html I was able to add a column with the order payment method on WooCommerce admin orders list
add_filter('manage_edit-shop_order_columns', 'misha_order_items_column' );
function misha_order_items_column( $order_columns ) {
$order_columns['order_payment_method'] = "Payment method";
return $order_columns;
}
add_action( 'manage_shop_order_posts_custom_column' , 'misha_order_items_column_cnt' );
function misha_order_items_column_cnt( $colname ) {
global $the_order; // the global order object
if( $colname == 'order_payment_method' ) {
// Get payment method
$payment_method = $the_order->get_payment_method();
echo $payment_method;
}
}
This works perfectly, and adds the desired statuses in the custom column
Then, based on a code I found, I made adjustments to add the filter
add_action('restrict_manage_posts', 'add_shop_order_filter_by_state');
function add_shop_order_filter_by_state(){
global $pagenow, $typenow, $the_order;
if( 'shop_order' === $typenow && 'edit.php' === $pagenow ) {
// Get payment method
$payment_method = $the_order->get_payment_method();
// Initializing
$filter_id = 'payment_method';
$current = isset($_GET[$filter_id])? $_GET[$filter_id] : '';
echo '<select name="'.$filter_id.'">
<option value="">'.__( 'Filter by payment method', 'woocommerce' )."</option>";
// Loop through shipping zones locations array
foreach( $payment_method as $method ) {
echo $method;
}
echo '</select>';
}
}
add_filter( 'request', 'process_admin_shop_order_filtering_by_state', 99 );
function process_admin_shop_order_filtering_by_state( $vars ) {
global $pagenow, $typenow;
$filter_id = 'payment_method';
if ( $pagenow == 'edit.php' && 'shop_order' === $typenow
&& isset( $_GET[$filter_id] ) && ! empty($_GET[$filter_id]) ) {
$vars['meta_key'] = 'payment_method';
$vars['meta_value'] = $_GET[$filter_id];
$vars['orderby'] = 'meta_value';
}
return $vars;
}
But because of those changes, in the 2nd part of my code I have an error in my log files:
"Uncaught Error: Call to a member function get_payment_method() on null".
It seems that the global variable $the_order is not recognized?
Although I don't immediately have an idea how I can apply this differently. Any adivce would be appreciated
