Woocommerce – Hide Completed Orders

add_filter( 'views_edit-shop_order', 'wc_hide_completed_link', 10, 1 );
function wc_hide_completed_link ($views) {
	$views['exclude-completed'] = sprintf('<a href="edit.php?exclude_order_status=wc-completed&post_type=shop_order">Hide completed orders</a>');
	return $views;
}

add_action( 'load-edit.php', 'wc_filter_completed' );
function wc_filter_completed() {
	global $typenow;
	if( 'shop_order' == $typenow ) {
		add_filter( 'posts_where' , 'posts_where_filter_completed' );
	}
}

function posts_where_filter_completed( $where ) {
	global $wpdb;       
	if ( is_admin() && isset( $_GET[ 'exclude_order_status' ] ) && !empty( $_GET[ 'exclude_order_status' ] ) ) {
		$status = $_GET[ 'exclude_order_status' ];
		$where .= " AND $wpdb->posts.post_status != '$status'";
	}
	return $where;
}

This code should be placed in the ‘Snippets’ plugin for wordpress or your sites child theme. This code was taken from this page on github.

Subscribe

SUBSCRIBE to get updates!

News on seasonal items, special markets and recipes. (Infrequent)

Related Posts