Woocommerce Order Status Dropdown Filter

Wordpress & WooCommerce

If you’ve got a WordPress website online and are interested in selling anything, WooCommerce is most possibly the manner to go. Powered with the aid of Automattic, it’s far by means of a long way the maximum famous e-trade plugin available for WordPress. It is supported by using a very massive network and it’s prolonged with themes and plugins by many third party authors.

Having established WooCommerce is pretty an awful lot a need while you need to sell something via a WordPress website, it stands to purpose that there are a few matters it can’t do, not out of the field anyway.

In our example we’d like to display per-product restock notices, to allow our customers to recognize whilst an out of stock product will be available for purchase. Lucky for us WooCommerce is extendable and we can obtain the favored outcome with only a few traces of code. Let’s begin.

We are going to add Order Status Dropdown to woocommerce Admin Order Listing Grid.

To Add Woocommerce Order Status Dropdown Filter use the following code to your function.php file of the current theme.
Path: /wp-content/themes/your-current-theme/function.php

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

// 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)

Leave a Reply

Your email address will not be published. Required fields are marked *