Skip to content

Instantly share code, notes, and snippets.

@btribouillet
Last active September 14, 2018 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save btribouillet/5ae99beb5f6f5063f50fdf84398fa625 to your computer and use it in GitHub Desktop.
Save btribouillet/5ae99beb5f6f5063f50fdf84398fa625 to your computer and use it in GitHub Desktop.
Feature request iconic delivery slots: Add an apply_filters in class-reservations.php (line 22 in gist)
/**
* Get reservations.
*
* @param int $processed 1/0
* @param string $operator
* @param string $order
*
* @return array
*/
public static function get_reservations( $processed = 1, $operator = '>=', $order = 'ASC' ) {
$return = array();
$key = md5( sprintf( '%s-%s-%s', $processed, $operator, $order ) );
if ( isset( $return[ $key ] ) ) {
return $return[ $key ];
}
global $wpdb, $jckwds;
$table_name = self::get_table_name();
/* START: THIS HAS BEEN ADDED */
$reservations_query = "
SELECT * FROM {$table_name}
WHERE date $operator CURDATE()
AND processed = $processed
ORDER BY date $order, starttime ASC
";
$reservations_query = apply_filters('iconic_wds_reservations_query', $reservations_query);
$reservations = $wpdb->get_results( $reservations_query, OBJECT );
/* END: THIS HAS BEEN ADDED */
if ( ! empty( $reservations ) ) {
foreach ( $reservations as $index => $reservation ) {
$reservation->order = wc_get_order( $reservation->order_id );
$reservation->iconic_wds = array(
'date_formatted' => Iconic_WDS_Helpers::get_date_formatted( $reservation->date ),
'starttime_formatted' => Iconic_WDS_Helpers::get_time_formatted( $reservation->starttime ),
'endtime_formatted' => Iconic_WDS_Helpers::get_time_formatted( $reservation->endtime ),
'same_day' => (bool) $reservation->order->get_meta( '_iconic_wds_is_same_day' ),
'next_day' => (bool) $reservation->order->get_meta( '_iconic_wds_is_next_day' ),
);
if ( ! empty( $reservation->order ) ) {
$reservation->order_status = $reservation->order->get_status();
$reservation->order_status_badge = Iconic_WDS_Order::get_status_badge( $reservation->order_status );
$reservation->order_edit = Iconic_WDS_Order::get_edit_order_link_html( $reservation->order_id );
$reservation->order_items = Iconic_WDS_Order::get_order_items( $reservation->order );
$reservation->shipping_method = $reservation->order->get_shipping_method();
$reservation->address_link = Iconic_WDS_Order::get_shipping_address_link_html( $reservation->order );
$reservation->billing_name = Iconic_WDS_Order::get_billing_full_name( $reservation->order );
$reservation->billing_email = Iconic_WDS_Order::get_billing_email_link_html( $reservation->order );
}
if ( is_numeric( $reservation->user_id ) && empty( $reservation->order ) ) {
$customer = get_userdata( $reservation->user_id );
$reservation->billing_name = Iconic_WDS_Helpers::get_user_name( $customer );
$reservation->billing_email = Iconic_WDS_Helpers::get_email_link_html( $customer->user_email );
}
}
}
$return[ $key ] = array(
'processed' => $processed,
'results' => $reservations,
);
return $return[ $key ];
}
function filter_reservations_query( $q ) {
// Modify query string here
return $q;
}
add_filter( 'iconic_wds_reservations_query', 'filter_reservations_query' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment