*/
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 '
';
// 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) . '';
}
}
}