WooCommerce Order Date Filter

SHARE
Table Of Contents

Introduction

Happy Saturday from the team at Titan Digital. We’re thrilled to introduce our first Insights release. This is about our simple & free WordPress plugin: “WooCommerce Order Date Filter”. Who is it for? Well, this easy-to-use plugin allows store owners to filter orders based on specific date ranges. It provides greater control and efficiency in managing sales and orders. Below, we’ve put together a step-by-step guide on how to install and use this simple tool, ensuring you can easily manage orders in your WooCommerce store!

Why did we do this? Well, it’s a request that’s come up a number of times on projects – specifically those store-owners dealing with higher order volumes. So instead of keeping it to ourselves, we thought we’d share it with you. No strings, just a download link below.

However, we’d ask that you consider subscribing to Insights (form at bottom of page) or following us on social media.

Download The Plugin Now

Using WooCommerce Order Date Filter

Installation

First things first, you’ll need to install the plugin on your WooCommerce site.

Follow these simple steps:

  1. Download the Plugin: Begin by downloading the file above.
  2. Upload to Your Site: Navigate to the WordPress admin dashboard, go to the ‘Plugins’ section, and click on ‘Add New’. Then, choose ‘Upload Plugin’ and select the downloaded file from your computer.
  3. Activate the Plugin: After the upload is complete, activate the plugin by clicking on ‘Activate Plugin’.

Setting Up

Once activated, the WooCommerce Order Date Range Filter plugin seamlessly integrates with your WooCommerce Orders panel.

To get started:

  1. Access Orders: Click on ‘WooCommerce’ and then ‘Orders’ in your dashboard.
  2. Find the Date Filter: You will notice a new date range filter option at the top of the orders page. It’s intuitive and designed to blend into your existing WooCommerce layout.

Using The Date Filter Plugin

To use the plugin, simply:

  1. Apply Filter: Once you have chosen your dates, click ‘Apply Filter’. The page will refresh, and only the orders that fall within your specified date range will be displayed.
  2. Set Date Ranges: Click on the date range fields to select the start and end dates for which you wish to filter orders. The plugin uses a calendar dropdown for easy date selection.

Benefits of Using the Plugin

  • Improved Order Management: Streamline order management by focusing on orders from particular dates, especially useful during promotions or after launching new products.
  • Time Efficiency: Quickly filter through orders without manually sorting through them, saving time and effort.
  • Sales Analysis: Easily analyze sales for specific periods, helping you understand trends and prepare better for future demands.

The Code

If you’re really interested in peering behind the scenes here is the code. If you’re familiar with PHP and Javascript it won’t be anything special – however we’d be thrilled to hear what you can do with it.

<?php
/**
 * Plugin Name: WooCommerce Order Date Range Filter
 * Plugin URI: https://titandigital.ie
 * Description: Adds a custom date range filter to the WooCommerce orders admin page.
 * Version: 1.0
 * Author: Titan Digital
 * Author URI: https://titandigital.ie
 */

// Enqueue the datepicker UI
add_action('admin_enqueue_scripts', 'woocommerce_load_admin_datepicker');
function woocommerce_load_admin_datepicker($hook) {
    global $typenow;

    if ($typenow == 'shop_order' && ($hook == 'edit.php')) {
        wp_enqueue_script('jquery-ui-datepicker');
        wp_enqueue_style('jquery-ui-css', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css');
    }
}

// Add date selector inputs
add_action('restrict_manage_posts', 'woocommerce_admin_orders_date_selector_filter', 20);
function woocommerce_admin_orders_date_selector_filter() {
    global $typenow;

    if ('shop_order' !== $typenow) {
        return;
    }

    $start_date = isset($_GET['start_date']) ? $_GET['start_date'] : '';
    $end_date = isset($_GET['end_date']) ? $_GET['end_date'] : '';

    echo '<input type="text" name="start_date" id="start_date" placeholder="' . esc_attr__('Start date...', 'woocommerce') . '" value="' . esc_attr($start_date) . '"/>';
    echo '<input type="text" name="end_date" id="end_date" placeholder="' . esc_attr__('End date...', 'woocommerce') . '" value="' . esc_attr($end_date) . '"/>';

    ?>
    <script type="text/javascript">
        jQuery(function($) {
            $('#start_date, #end_date').datepicker({
                dateFormat: 'yy-mm-dd'
            });
        });
    </script>
    <?php
}

// Modify the query based on selected dates
add_filter('request', 'woocommerce_filter_orders_by_date_range');
function woocommerce_filter_orders_by_date_range($vars) {
    global $typenow;

    if ('shop_order' === $typenow && isset($_GET['start_date']) && isset($_GET['end_date']) && !empty($_GET['start_date']) && !empty($_GET['end_date'])) {
        $start_date = date('Y-m-d', strtotime($_GET['start_date']));
        $end_date = date('Y-m-d', strtotime($_GET['end_date']));

        $vars['date_query'] = array(
            array(
                'after'     => $start_date,
                'before'    => $end_date,
                'inclusive' => true,
            ),
        );
    }

    return $vars;
}

Disclaimer

This file & code is offered as-is and comes with no liability for Titan Digital Limited. When you choose to download and use it, you do so of your own free will and understand that we are not obliged to provide support and agree Titan Digital are not liable for any issues that may arise. You use it at your own risk.

Subscribe To Insights