| 1 |
<?php |
| 2 |
|
| 3 |
namespace MakeCommerce\Shipping\Method\Courier; |
| 4 |
|
| 5 |
/** |
| 6 |
* Specifics for Smartpost courier shipping method |
| 7 |
* |
| 8 |
* @since 3.0.0 |
| 9 |
*/ |
| 10 |
|
| 11 |
class Smartpost extends \MakeCommerce\Shipping\Method\Courier { |
| 12 |
|
| 13 |
public $carrier = "Smartpost"; |
| 14 |
public $service_name = "eservice.smartpost.ee"; |
| 15 |
public $default_price = "4.95"; |
| 16 |
public $default_max_weight = "60"; |
| 17 |
|
| 18 |
/** |
| 19 |
* Loads all form fields specific to this shipping method |
| 20 |
* |
| 21 |
* @since 3.0.0 |
| 22 |
*/ |
| 23 |
public function initialize_method_form_fields() { |
| 24 |
|
| 25 |
//Nothing to see here, move along |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Set method specific hooks/filters |
| 30 |
* |
| 31 |
* @since 3.0.0 |
| 32 |
*/ |
| 33 |
public function set_method_hooks() { |
| 34 |
|
| 35 |
add_filter( 'woocommerce_review_order_after_shipping' , array( $this, 'add_smartpost_courier_checkout_fields' ) ); |
| 36 |
add_action( 'woocommerce_checkout_update_order_meta', array( $this, 'add_order_meta' ) ); |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Adds courier arrival time select option to checkout fields |
| 41 |
* |
| 42 |
* @since 3.0.0 |
| 43 |
*/ |
| 44 |
public function add_smartpost_courier_checkout_fields( $fragment ) { |
| 45 |
|
| 46 |
echo ' |
| 47 |
<tr style="display: none;" class="parcel_machine_checkout parcel_machine_checkout_courier_' . mb_strtolower($this->ext ) . '"> |
| 48 |
<td colspan="2"> |
| 49 |
<p class="form-row" id="' . esc_attr( $this->id ) . '_field"> |
| 50 |
<label class="courier_arrival_time_window_label">'.__('Pick courier arrival time window', 'wc_makecommerce_domain').'</label> |
| 51 |
|
| 52 |
<select class="select parcel-machine-select-box-time" name="' . esc_attr( $this->id ) . '" id="' . esc_attr( $this->id ) . '"> |
| 53 |
<option value="1">' . __( 'Any time', 'wc_makecommerce_domain' ) . '</option> |
| 54 |
<option value="2">' . __( 'Worktime (09:00..17:00)', 'wc_makecommerce_domain' ) . '</option> |
| 55 |
<option value="3">' . __( 'After worktime (17:00..21:00)', 'wc_makecommerce_domain' ) . '</option> |
| 56 |
</select> |
| 57 |
</p> |
| 58 |
</td> |
| 59 |
</tr> |
| 60 |
'; |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* Adds delivery time option to order metadata |
| 65 |
* |
| 66 |
* @since 3.0.0 |
| 67 |
*/ |
| 68 |
public function add_order_meta( $order_id ) { |
| 69 |
|
| 70 |
if ( !empty( $_POST[$this->id] ) ) { |
| 71 |
update_post_meta( $order_id, '_delivery_time', sanitize_text_field( $_POST[$this->id] ) ); |
| 72 |
} |
| 73 |
} |
| 74 |
} |