Hi,
So this will add a dropdown list at the top of the orders list that allows to see only the orders when the invoices are in a specific month.
// add a dropdown list with months
add_action( 'restrict_manage_posts', 'display_admin_shop_order_by_invoice_date' );
function display_admin_shop_order_by_invoice_date()
{
global $pagenow, $typenow;
$months = array('January','February','March','April','May','June','July','August','September','October','November','December') ;
if( 'shop_order' === $typenow && 'edit.php' === $pagenow )
{
$domain = 'woocommerce';
$filter_id = 'filter_order_by_invoice_date';
$currmonth = date('n') ;
$curryear = date('Y') ;
echo '<select name="'.$filter_id.'">
<option value="">' . __('All invoice dates', $domain) . '</option>';
for ($i = 0; $i < 12; $i++)
{
$x = (12 + $currmonth - $i - 1) % 12 + 1;
if ($x == 12)
{$curryear--;}
printf( '<option value="' . $x . '-' . $curryear . '">' . $months[$x-1] . ' ' . $curryear . '</option>');
}
echo '</select>';
}
}
add_filter( 'pre_get_posts', 'filter_orders_by_pdf_invoice_date', 99, 1 );
function filter_orders_by_pdf_invoice_date( $query )
{
if ( ! is_admin() )
{ return $query; }
global $pagenow;
if ( 'edit.php' === $pagenow && 'shop_order' === $query->query['post_type'] )
{
$domain = 'woocommerce';
$filter_id = 'filter_order_by_invoice_date';
// We only need o modify a query if an option is given
if (isset( $_GET[$filter_id] ) && ! empty($_GET[$filter_id]))
{
$currentfilter = $_GET[$filter_id] ;
$i = strpos($currentfilter,'-') ;
$filtermonth = substr($currentfilter,0,$i) ;
$filteryear = substr($currentfilter,$i+1,strlen($currentfilter)) ;
$startmonth = $filteryear . '-' . $filtermonth . '-1' ;
$endmonth = $filteryear . '-' . $filtermonth . '-' . date('t',strtotime($currentfilter)) ;
$meta_query[] = array(
'relation' => 'AND',
array(
'key' => '_wcpdf_invoice_date_formatted',
'value' => $startmonth,
'compare' => '>=',
'type' => 'DATE'
),
array(
'key' => '_wcpdf_invoice_date_formatted',
'value' => $endmonth,
'compare' => '<=',
'type' => 'DATE'
)
);
$query->set( 'meta_query', $meta_query );
}
}
return $query;
}
-
This reply was modified 3 years, 2 months ago by
aqdennis.