*/ class Aw_Rider_Traking_Admin { /** * The ID of this plugin. * * @since 1.0.0 * @access private * @var string $plugin_name The ID of this plugin. */ private $plugin_name; /** * The version of this plugin. * * @since 1.0.0 * @access private * @var string $version The current version of this plugin. */ private $version; /** * Initialize the class and set its properties. * * @since 1.0.0 * @param string $plugin_name The name of this plugin. * @param string $version The version of this plugin. */ public function __construct( $plugin_name, $version ) { $this->plugin_name = $plugin_name; $this->version = $version; } /** * Register the stylesheets for the admin area. * * @since 1.0.0 */ public function enqueue_styles() { /** * This function is provided for demonstration purposes only. * * An instance of this class should be passed to the run() function * defined in Aw_Rider_Traking_Loader as all of the hooks are defined * in that particular class. * * The Aw_Rider_Traking_Loader will then create the relationship * between the defined hooks and the functions defined in this * class. */ wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/aw-rider-traking-admin.css', array(), $this->version, 'all' ); } /** * Register the JavaScript for the admin area. * * @since 1.0.0 */ public function enqueue_scripts() { /** * This function is provided for demonstration purposes only. * * An instance of this class should be passed to the run() function * defined in Aw_Rider_Traking_Loader as all of the hooks are defined * in that particular class. * * The Aw_Rider_Traking_Loader will then create the relationship * between the defined hooks and the functions defined in this * class. */ wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/aw-rider-traking-admin.js', array( 'jquery' ), $this->version, false ); } public function init_functions(){ add_rewrite_endpoint( 'assigned-orders', EP_PAGES ); add_rewrite_endpoint( 'aw-order-traking', EP_PAGES ); // Add new role $roles_set = get_option('driver_role_is_set'); if(!$roles_set){ add_role('Driver', 'Driver', array( 'read' => true, // True allows that capability, False specifically removes it. 'edit_posts' => true, 'delete_posts' => true, 'upload_files' => true )); update_option('driver_role_is_set',true); } } public function add_custom_field_to_orders_page($order){ $args = array( 'role' => 'Driver', 'order' => 'ASC' ); $users = get_users( $args ); if(!empty($users)){ $get_rider = $order->get_meta( '_select_aw_driver' ); $options[''] = __( 'Select a rider', 'woocommerce'); // default value foreach ($users as $key => $user) { $user_id = $user->ID; $user_name = $user->user_firstname; $options[$user_id] = $user_name; } echo '
'; woocommerce_wp_select( array( 'id' => '_select_aw_driver', 'label' => __( 'Assign this order to a driver', 'woocommerce' ), 'options' => $options, //this is where I am having trouble 'value' => $get_rider, ) ); echo '
'; } } public function save_custom_field( $order_id ){ update_post_meta( $order_id, '_select_aw_driver', wc_clean( $_POST[ '_select_aw_driver' ] ) ); } function user_has_role($user_id, $role_name) { $user_meta = get_userdata($user_id); $user_roles = $user_meta->roles; return in_array($role_name, $user_roles); } public function add_rider_tab_myaccount_page( $menu_links ){ $current_user_id = get_current_user_id(); $user_is_driver = $this->user_has_role($current_user_id, 'Driver'); $user_is_customer = $this->user_has_role($current_user_id, 'customer'); if(!empty($user_is_driver)){ $menu_links = array_slice( $menu_links, 0, 5, true ) + array( 'assigned-orders' => 'Assigned Orders' ) + array_slice( $menu_links, 5, NULL, true ); } // if(!empty($user_is_customer)){ // $menu_links = array_slice( $menu_links, 0, 5, true ) // + array( 'aw-order-traking' => 'Order Traking' ) // + array_slice( $menu_links, 6, NULL, true ); // } return $menu_links; } public function order_traking_page_content() { if(!empty(@$_GET['order_id'])){ $driver_id = get_post_meta($_GET['order_id'], '_select_aw_driver', true); $driver_lat_lng = json_decode(get_user_meta($driver_id, 'current_lat_lng', true)); $driver_lat = $driver_lat_lng->latitude; $driver_lng = $driver_lat_lng->longitude; $order = wc_get_order( $_GET['order_id'] ); $customer_shipping_address_1 = $order->get_shipping_address_1(); $customer_shipping_address_2 = $order->get_shipping_address_2(); ?>

Total Distance:

Estimated Time:

request ); ?> get_items( apply_filters( 'woocommerce_purchase_order_item_types', 'line_item' ) ); $show_purchase_note = $order->has_status( apply_filters( 'woocommerce_purchase_note_order_statuses', array( 'completed', 'processing' ) ) ); $show_customer_details = is_user_logged_in() && $order->get_user_id() === get_current_user_id(); $downloads = $order->get_downloadable_items(); $show_downloads = $order->has_downloadable_item() && $order->is_download_permitted(); if ( $show_downloads ) { wc_get_template( 'order/order-downloads.php', array( 'downloads' => $downloads, 'show_title' => true, ) ); } ?>

$item ) { $product = $item->get_product(); wc_get_template( 'order/order-details-item.php', array( 'order' => $order, 'item_id' => $item_id, 'item' => $item, 'show_purchase_note' => $show_purchase_note, 'purchase_note' => $product ? $product->get_purchase_note() : '', 'product' => $product, ) ); } do_action( 'woocommerce_order_details_after_order_table_items', $order ); ?> get_order_item_totals() as $key => $total ) { ?> get_customer_note() ) : ?>
get_customer_note() ) ) ); ?>
$order ) ); }else{ $args = array( // Accepts a string: one of 'pending', 'processing', 'on-hold', 'completed', 'refunded, 'failed', 'cancelled', or a custom order status. 'meta_key' => '_select_aw_driver', 'meta_value' => $current_user_id, 'meta_compare' => '=', 'return' => 'objects' ); ?> On Route $order) { $item_count = $order->get_item_count(); ?>
Order Date Status Total Action
get_order_number(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> get_date_created() ) ); ?> get_status() ) ); ?> get_formatted_order_total(), $item_count ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> has_status('completed') ) { }else{ ?> Delivered View
'; // print_r($user->roles); // echo ''; } } public function add_my_account_my_orders_order_traking( $actions, $order ) { $action_slug = 'aw-order-traking'; $actions[$action_slug] = array( 'url' => get_site_url().'/my-account/aw-order-traking/?track_order=true&order_id='.$order->get_id(), 'name' => 'Track Order', ); return $actions; } public function add_filter(){ global $wpdb, $table_prefix; $post_type = (isset($_GET['post_type'])) ? $_GET['post_type'] : 'post'; //only add filter to post type you want if ($post_type == 'shop_order'){ //query database to get a list of years for the specific post type: $args = array( 'role' => 'Driver', 'order' => 'ASC' ); $users = get_users( $args ); // echo '
';
// 			 					print_r($users);
// 			 					echo '
'; if(!empty($users)){ ?> get_status() != 'processing'){ continue; } update_post_meta($post, '_select_aw_driver', $chef_name); } wp_redirect(admin_url('edit.php?post_type=shop_order')); } } public function adding_columns_to_shop_order( $columns){ $columns['user_id'] = __( 'Driver Name' ); return $columns; } public function smashing_shop_order_column( $column, $post_id ){ if ( $column == 'user_id' ) { echo ''.get_post_meta($post_id, '_select_aw_driver',true) . ''; } } }