Skip to content

Instantly share code, notes, and snippets.

@Spreeuw
Created August 4, 2015 11:39
Show Gist options
  • Save Spreeuw/b3ca49c021390f700021 to your computer and use it in GitHub Desktop.
Save Spreeuw/b3ca49c021390f700021 to your computer and use it in GitHub Desktop.
link to hide completed orders in woocommerce
<?php
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;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment