• Hi,

    At the moment it’s only possible to show the Invoice number in the order list in the backend, but it would be great to also be able to show the Invoice date and be able to filter on it.

    For the monthly VAT reclamation I have to book orders on invoice date rather than order date, and especially for credit card payments there can be several days in between order date and invoice date, moving invoice date into the next month so that it should be booked in another month than the original order.

    Thanks,

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor alexmigf

    (@alexmigf)

    Thread Starter aqdennis

    (@aqdennis)

    Hi @alexmigf,

    I have extended it a bit with a snippet that adds a dropdown to filter the orders on invoice date per month. So basically the same as the dropdown to filter on order date, but then on invoice date.

    If your interest, or anybody else, where could I post it or send it too? Here?

    Cheer,
    Dennis

    • This reply was modified 3 years, 2 months ago by aqdennis.
    Plugin Contributor Yordan Soares

    (@yordansoares)

    Hi @aqdennis,

    I’m glad to know that you managed to make it work, and even improve the code snippet! And yes, it would be helpful to share it here. You can wrap your code between backquotes (`) to format your snippet as code content.

    Thanks for your feedback!

    Thread Starter aqdennis

    (@aqdennis)

    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.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Invoice date in backend order list’ is closed to new replies.