Vendor Orders Page – Date Query Bug
-
Hi there,
I just wanted to report an issue that I’ve been experiencing with WC-Vendors for quite some time, that I actually mananaged to resolve today after a lot of debugging.
Basically, I was having issues with the Dashboard Orders Page around the Date Range selection and this not properly showing results/orders for a specified start_date and end_date range when submitting the page with the date range filter. If you ran the filter / submitted it a second time, it usually would work and then show orders for this specified range, but sometimes it would not.
This was driving me nuts so I started investigating, and it was like the
$_POST['start_date']
and$_POST['end_date']
were NOT being passed properly, but indeed they were.Then while debugging I discovered that the
$_POST['start_date']
and$_POST['end_date']
values are defined via the/classes/class-queries.php
page, and that the logic for setting and getting these date range values is actually incorrect and is what was causing my issues.More speicifically, I has to reverse the logic for this
orders_within_range
function so that it would SET the wcv_order_start_date and wcv_order_end_date session variables BEFORE it would GET them.This is the updated function that has fixed the issue for me and is working BEAUTIFULLY:
public static function orders_within_range() { global $start_date, $end_date; if ( ! empty( $_POST['start_date'] ) ) { WC()->session->set( 'wcv_order_start_date', strtotime( $_POST['start_date'] ) ); } if ( ! empty( $_POST['end_date'] ) ) { WC()->session->set( 'wcv_order_end_date', strtotime( $_POST['end_date'] ) ); } $start_date = WC()->session->get( 'wcv_order_start_date', strtotime( current_time( 'Y-M' ) . '-01' ) ); $end_date = WC()->session->get( 'wcv_order_end_date', current_time( 'timestamp' ) ); $after = date( 'Y-m-d', $start_date ); $before = date( 'Y-m-d', strtotime( '+1 day', $end_date ) ); return apply_filters( 'wcvendors_orders_date_range', array( 'after' => $after, 'before' => $before, ) ); }
Hope this helps anyone else from pulling thier hair out trying to debug a similar issue!!
- The topic ‘Vendor Orders Page – Date Query Bug’ is closed to new replies.