Last active
June 3, 2020 12:13
-
-
Save btribouillet/570d4fe4afaa92dfbf60567cbdbf55cc to your computer and use it in GitHub Desktop.
example for iconic_wds_get_reservations_query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'iconic_wds_get_reservations_query', array( __CLASS__, 'filter_deliveries_per_warehouse' ) ); | |
/** | |
* Filter deliveries per warehouse | |
* | |
* @param string $q WordPress SQL query statement. | |
* @return mixed | |
*/ | |
public static function filter_deliveries_per_warehouse( $q ) { | |
if ( is_user_logged_in() ) { | |
$user = wp_get_current_user(); | |
$roles = (array) $user->roles; | |
if ( in_array( 'courier', $roles, true ) ) { | |
global $wpdb; | |
$warehouse_id = Vmm_Helpers::get_user_connected_warehouse_id( $user ); | |
$needle = 'FROM ' . $wpdb->prefix . 'jckwds'; | |
$join = $needle . ' JOIN ' . $wpdb->prefix . 'vmm_order_to_warehouse ON ' . $wpdb->prefix . 'vmm_order_to_warehouse.order_id = ' . $wpdb->prefix . 'jckwds.order_id AND ' . $wpdb->prefix . 'vmm_order_to_warehouse .warehouse_id = ' . $warehouse_id; | |
$q = str_replace( $needle, $join, $q ); | |
} | |
} | |
return $q; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment