• This is a really great enhancement – but (always a but) unfortunately when activated you cannot see orders that have been placed into ‘trash’, even though they still show up as a row count in the menu eg. trash(2).

    Deactivating the plugin lets orders with [post_status=trash] show up again, I’ve also confirmed this glitch with another relatively clean WP install with all other plugins deactivated. Same result.

    FYI orders look perfectly fine in the DB tables and since they work fine with the plugin deactivated I don’t think the data is the issue.

    As every other [post_status] is fine NOR can I find any other glitches on the page I don’t think this is a coding error, rather I suspect the looping code that is being modified to link products with the orders(to allow filtering) simply isn’t finding records with [post_status=trash].

    Because all other order status works fine this suggests woocommerce handles records with [post_status=trash] slightly differently – though that’s way beyond my expertise.

    This also explains why the menu still shows up a ‘trash’ count – the code here probably isn’t modified at all.

    Admittedly this isn’t something many users would even worry about too much. However in my case the client will have back-end access (highly restricted) and this will be confusing.

    So I’ve had to hard-code out the Woocommerce ‘trash’ references but obviously I’d prefer *not* to do that to woocommerce files. I’ve emailed the developer and are waiting to hear back – I’m happy to hard code in any required changes ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • Same case here.

    There’s some questionable practices code wise in certain function where order IDs are retrieved even if specific URL parameters (used for filtering) are not present this performing unneeded DB query(-ies), on top of that it modifies query arg posts__in/posts__not_in which screws up displaying orders that are trashed. So here’s my solution which should fix both things and plugin still works properly:

    Located in:
    wc-search-orders-by-product\includes\admin\class-wc-search-orders-by-product-admin.php

    OLD function:

    	public function sobp_filter_orders( $query_vars ) {
    		global $typenow;
    		if ( in_array( $typenow, wc_get_order_types( 'order-meta-boxes' ), true ) ) {
    
    			$order_ids = self::get_order_ids();
    
    			// filter order IDs based on additional filtering criteria (products, product categories and product type).
    			if ( ! empty( $_GET['search_product_type'] ) ) {
    				$order_ids = self::order_ids_by_product_type( $_GET['search_product_type'] );
    			}
    
    			if ( ! empty( $order_ids ) && ! empty( $_GET['product_id'] ) ) {
    
    				$order_ids = self::filter_orders_containing_products( $order_ids, $_GET['product_id'] );
    			}
    
    			if ( ! empty( $order_ids ) && ! empty( $_GET['search_product_cat'] ) ) {
    
    				$order_ids = self::filter_orders_containing_product_categories( $order_ids, $_GET['search_product_cat'] );
    			}
    
    			if ( empty( $order_ids ) ) {
    				$query_vars['post__in'] = array( 0 );
    			} else {
    				$final_order_ids = array_unique( $order_ids );
    				$query_vars['post__in'] = $final_order_ids;
    			}
    		}
    
    		return $query_vars;
    	}

    How it should look like:

    	public function sobp_filter_orders( $query_vars ) {
    
    		if ( $this->is_active_on_post_type() ) {
    
                if ( ! empty( $_GET['search_product_type'] ) || ! empty( $_GET['product_id'] ) || ! empty( $_GET['search_product_cat'] ) ) {
    
                    $order_ids = self::get_order_ids();
    
                    // filter order IDs based on additional filtering criteria (products, product categories and product type).
                    if ( ! empty( $_GET['search_product_type'] ) ) {
                        $order_ids = self::order_ids_by_product_type( $_GET['search_product_type'] );
                    }
    
                    if ( ! empty( $order_ids ) && ! empty( $_GET['product_id'] ) ) {
                        $order_ids = self::filter_orders_containing_products( $order_ids, $_GET['product_id'] );
                    }
    
                    if ( ! empty( $order_ids ) && ! empty( $_GET['search_product_cat'] ) ) {
                        $order_ids = self::filter_orders_containing_product_categories( $order_ids, $_GET['search_product_cat'] );
                    }
    
                    if ( empty( $order_ids ) ) {
                        $query_vars['post__in'] = array( 0 );
                    } else {
                        $final_order_ids = array_unique( $order_ids );
                        $query_vars['post__in'] = $final_order_ids;
                    }
                    
                }
    		}
    
    		return $query_vars;
    	}

    Same problem here, however the code suggested above is not the appropriate fix.
    The issue is really in the function get_order_ids() which uses the Woo function wc_get_order_statuses(); to query the active orders by known statuses.

    The post_status “Trash” is not returned by wc_get_order_statuses();.

    So the fix would be to simply add this minor change in the get_order_ids() function.

    $default_order_statuses = array_keys( (array) wc_get_order_statuses() );
    $default_order_statuses[] = 'trash';

    This way the returned ID’s used by the plugin also takes the trashed orders into account.
    Please fix this in the next release of the plugin!

    @egmdev your solution is ok if you wanted to actually perform a search on orders that are in the trash, but in the majority of cases you wouldn’t,- after all these orders are in the trash.

    Main issue is that search actions are being performed while you are sorting orders by status ‘trash’, even if you did not perform the search by product, so your solution is more of “going around it” instead of optimizing the whole function to run only when it needs to run and on orders that matter.

    @vlaskiz ; Hey Andrius, Your answer here helped me as well. Thanks for this

    Bence Fodor

    (@webmotion)

    The issue still exists, no orders show up under wp-admin/edit.php?post_status=trash&post_type=shop_order if the plugin is active, and after I deactivate it, I can see them all.

    This is disappointing that plugin author is not addressing this problem or any others in plugin’s support forum. Definitely deleting this plugin. I have same issue reported here.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Plugin hides orders with status ‘trash’’ is closed to new replies.