A Guide to Add WooCommerce Order Status Dropdown filter

If you wish to sell online on WordPress, then WooCommerce is a mandate for you! Without WooCommerce, one cannot imagine setting up a smooth online store. It is powered by Automattic and famous for e-trade. Also, this plugin is full of various themes and filters. Further, in this tutorial, we will learn how to enable WooCommerce Order Status Dropdown filter.

Even though WooCommerce has several functionalities, it does not have a few useful functions. However, these are not out of your scope. WooCommerce is extendable. So, you can obtain the favored outcome by implementing a few coding operations. 

In this tutorial, we will display per-product restock notices. This way, you will be able to alert your customers. So, they will get notified as soon as the out of stock product becomes available for purchase.

Furthermore, we will learn to add order status dropdown. It will be added to WooCommerce Admin Order Listing Grid.

So, you can add the following code to your  current theme’s function.php file. Ultimately, this will enable the WooCommerce Order Status Dropdown filter functionality.

Path: /wp-content/themes/your-current-theme/function.php

// Add Order Status Dropdown Filter Start Here (phpsof.com)
add_action( 'restrict_manage_posts','phpsof_filter_orders_by_orderstatus');
function phpsof_filter_orders_by_orderstatus() {
		global $typenow;
		if ( 'shop_order' === $typenow ) {
		// get all stores, even inactive ones
		 $order_statuses = wc_get_order_statuses();
		?>
		<select name="_shop_order_status" id="_shop_order_status">
		<option value="">
			<?php esc_html_e( 'All Statues', 'wc-filter-orders-by-status' ); ?>
		</option>	
		<?php
          foreach ( $order_statuses as $key=>$statusname ) {
		?>
			<option value="<?php echo esc_html($key); ?>" <?php echo esc_attr( isset( $_GET['_shop_order_status'] ) ? selected(esc_html($key), $_GET['_shop_order_status'], false ) : '' ); ?>>
				<?php echo esc_html($statusname); ?>
			</option>
		<?php
            }
		?>
		</select>
		<?php
        }  
		}
add_filter( 'request','phpsof_filter_orders_by_orderstatus_query');
function phpsof_filter_orders_by_orderstatus_query( $vars ) {
	global $typenow;
	if ( 'shop_order' === $typenow && isset( $_GET['_shop_order_status'] ) && ! empty( $_GET['_shop_order_status'] ) ) {
		$vars['post_status'] = wc_clean( $_GET['_shop_order_status'] );
	}
	return $vars;
}
// Add Order Status Dropdown Filter End Here (phpsof.com)

You can get a descriptive idea by watching our Youtube Video.

https://www.youtube.com/watch?v=Hu1Y-WRGENo

[sociallocker]<a class="wp-block-buttons" href="https://www.phpsof.com/wp-
content/uploads/2020/05/phpsof-woocommerce-order-filter.zip">Download 
Woocommerce Admin Order Status Dropdown Filter
</a>[/sociallocker]

Also Read, WooCommerce Get Product Info (ID SKU $) from $product object

WooCommerce Get Order Info total items from $order Object