How to add date filter for Frontend Manager dashboard

First we have to hook the field template in the filter form
Note: Frontend Manager Filter has two action hooks. wpcfe_before_shipment_filters and wpcfe_after_shipment_filters. In this sample code will use the wpcfe_after_shipment_filters action hook.

Copy and paste this code in your functions.php file in you active theme. Please follow the template structure so that it will not destroy filter form layout.

function wpcfe_after_shipment_filters_callback(){
    ?>   
    <div class="form-group">
        <label for="wpcargo_filter_date_from">Date From: </label>
        <input id="wpcargo_filter_date_from" type="text" class="form-control wpccf-datepicker bg-white" name="wpcargo_filter_date_from" value="">
	</div>
	<div class="form-group">
        <label for="wpcargo_filter_date_to">Date To: </label>
        <input id="wpcargo_filter_date_to" type="text" class="form-control wpccf-datepicker bg-white" name="wpcargo_filter_date_to" value="">
	</div>		
    <?php
}
add_action('wpcfe_after_shipment_filters', 'wpcfe_after_shipment_filters_callback');

Now, We inserted our custom filter fields in the form. Let’s add another action filter to add out filter data in the shipment query arguments using the wpcfe_dashboard_meta_query filter.

Note: wpcfe_dashboard_meta_query filter accepts only one argument ( $meta_query ).

Copy and paste this code in you functions.php file in you active theme.

function custom_wpcfe_dashboard_arguments( $args ){
    /*
     * Note: $_GET['wpcargo_filter_date_from'] and $_GET['wpcargo_filter_date_to'] are the fields name of our custom filter field
     * 
     */

    $date_from  = isset($_GET['wpcargo_filter_date_from'])? $_GET['wpcargo_filter_date_from'] : '';
    $date_to    = isset($_GET['wpcargo_filter_date_to'])? $_GET['wpcargo_filter_date_to'] : '';

    if( !empty( $date_from  && !empty( $date_to ) ) ){
        $args['date_query'] = array(
            'after'     => $date_from,
            'before'    => $date_to,
            'inclusive' => true,
        );
    }
    return $args;
}
add_filter( 'wpcfe_dashboard_arguments', 'custom_wpcfe_dashboard_arguments' );
0
    0
    Your Cart
    Your cart is emptyReturn to Shop