Skip to content

Commit

Permalink
📦 NEW: Driver availability option
Browse files Browse the repository at this point in the history
  • Loading branch information
robertdevore committed Aug 7, 2019
1 parent f637242 commit b53400d
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 2 deletions.
25 changes: 25 additions & 0 deletions admin/class-ddwc-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,28 @@ function ddwc_delivery_driver_settings() {
}
add_action( 'wp_ajax_ddwc_delivery_driver_settings', 'ddwc_delivery_driver_settings' );
//add_action('wp_ajax_nopriv_ddwc_delivery_driver_settings', 'ddwc_delivery_driver_settings');

/**
* AJAX function to update driver availability
*
* @since 2.3
*/
function ddwc_driver_availability_update() {

$user_id = $_POST['user_id'];
$meta_value = $_POST['metavalue'];

if ( 'checked' == $meta_value ) {
$new_value = 'on';
$old_value = '';
} else {
$new_value = '';
$old_value = 'on';
}

// Update driver availability.
update_user_meta( $user_id, 'ddwc_driver_availability', $new_value, $old_value );

}
add_action( 'wp_ajax_ddwc_driver_availability_update', 'ddwc_driver_availability_update' );
add_action( 'wp_ajax_nopriv_ddwc_driver_availability_update', 'ddwc_driver_availability_update' );
26 changes: 26 additions & 0 deletions public/class-ddwc-public.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,34 @@ public function enqueue_scripts() {
wp_enqueue_script( $this->plugin_name . '-star-rating', 'https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js', array( 'jquery' ), $this->version, false );
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/ddwc-public.js', array( 'jquery' ), $this->version, false );
wp_localize_script( $this->plugin_name, 'WPaAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
} elseif ( is_wc_endpoint_url( 'driver-dashboard' ) ) {
wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/ddwc-public.js', array( 'jquery' ), $this->version, false );
wp_localize_script( $this->plugin_name, 'WPaAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
}

}

}

/**
* Driver availability option on Driver Dashboard
*
* @since 2.3
*/
function ddwc_driver_dashboard_driver_availability() {
// Driver availability.
if ( get_user_meta( get_current_user_id(), 'ddwc_driver_availability', true ) ) {
$checked = 'checked';
} else {
$checked = '';
}

echo '<div class="ddwc-availability">
<h4>' . __( 'Accepting deliveries', 'ddwc' ) . '</h4>
<label class="switch">
<input id="' . get_current_user_id() . '" type="checkbox" ' . $checked . ' />
<span class="slider round"></span>
</label>
</div>';
}
add_action( 'ddwc_assigned_orders_title_before', 'ddwc_driver_dashboard_driver_availability' );
91 changes: 90 additions & 1 deletion public/css/ddwc-public.css
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,93 @@ input.ddwc-ofdmsg {
.ddwc-pro-sms-updates h3 {
font-size: 24px;
margin-bottom: 12px;
}
}

/** Driver Dashboard - Driver availability */

.ddwc-availability {
background: #eee;
border: 1px solid #ddd;
padding: 5px;
margin-bottom: 24px;
}

@media screen and (max-width: 767px) {
.ddwc-availability {
margin-top: 24px;
}
}

.ddwc-availability h4 {
font-size: 20px;
display: inline-block;
line-height: 34px;
margin: 0 0 0 5px;
}
.ddwc-availability label.switch {
float: right;
margin-top: 2px;
}

/* The switch - the box around the slider */
.ddwc-availability .switch {
position: relative;
display: inline-block;
width: 60px;
height: 30px;
}

/* Hide default HTML checkbox */
.ddwc-availability .switch input {
opacity: 0;
width: 0;
height: 0;
}

/* The slider */
.ddwc-availability .switch .slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
}

.ddwc-availability .switch .slider:before {
position: absolute;
content: "";
height: 22px;
width: 22px;
left: 4px;
bottom: 4px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
}

.ddwc-availability input:checked + .slider {
background-color: #76bd1d;
}

.ddwc-availability input:focus + .slider {
box-shadow: 0 0 1px #76bd1d;
}

.ddwc-availability input:checked + .slider:before {
-webkit-transform: translateX(28px);
-ms-transform: translateX(28px);
transform: translateX(28px);
}

/* Rounded sliders */
.ddwc-availability .switch .slider.round {
border-radius: 22px;
}

.ddwc-availability .switch .slider.round:before {
border-radius: 50%;
}
2 changes: 1 addition & 1 deletion public/css/ddwc-public.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions public/js/ddwc-public.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b53400d

Please sign in to comment.