PluginProbe
MakeCommerce for WooCommerce / 4.1.0
MakeCommerce for WooCommerce v4.1.0
4.1.0 4.0.8 trunk 1.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 2.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2.0 2.2.1 2.2.2 All 96 releases
makecommerce / shipping / method / courier / smartpost.php

smartpost.php in MakeCommerce for WooCommerce 4.1.0, at shipping/method/courier/smartpost.php

112 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 use \MakeCommerce\Shipping\Method\Common\Smartpost;
14
15 public $default_price = "4.95";
16 public $default_max_weight = "60";
17
18 /**
19 * Overrides Method class function
20 * Removes loading of user and password fields
21 *
22 * @since 3.3.0
23 */
24 public function initialize_method_type_form_fields() {
25
26 //Initialize method specific fields
27 $this->initialize_method_form_fields();
28 }
29
30 /**
31 * Loads all form fields specific to this shipping method
32 *
33 * @since 3.0.0
34 */
35 public function initialize_method_form_fields() {
36
37 $this->initialize_smartpost_api_field();
38 }
39
40 /**
41 * Set method specific hooks/filters
42 *
43 * @since 3.0.0
44 */
45 public function set_method_hooks() {
46
47 $priority = 15;
48
49 add_action( 'woocommerce_checkout_update_order_meta', array( $this, 'add_order_meta' ) );
50
51 if ( ! $this->check_filter_hook_initialization( 'woocommerce_review_order_after_shipping', $priority ) ) {
52 add_filter( 'woocommerce_review_order_after_shipping' , array( $this, 'add_smartpost_courier_checkout_fields' ), $priority );
53 }
54 }
55
56 /**
57 * Adds courier arrival time select option to checkout fields
58 *
59 * @since 3.0.0
60 */
61 public function add_smartpost_courier_checkout_fields( $fragment ) {
62
63 echo self::prepare_smartpost_courier_checkout_fields( $this->id );
64 }
65
66 public static function prepare_smartpost_courier_checkout_fields( $id, $table = true ) {
67 $ext = explode( '_', $id )[1];
68
69 if ( !$table ) {
70 return '
71 <p class="smartpost-courier-text">'.__('Pick courier arrival time window', 'wc_makecommerce_domain').'</p>
72 <p class="form-row smartpost-courier-text" id="' . esc_attr( $id ) . '_field">
73 <select class="select parcel-machine-select-box-time" name="' . esc_attr( $id ) . '" id="' . esc_attr( $id ) . '">
74 <option value="1">' . __( 'Any time', 'wc_makecommerce_domain' ) . '</option>
75 <option value="2">' . __( 'Worktime (09:00..17:00)', 'wc_makecommerce_domain' ) . '</option>
76 <option value="3">' . __( 'After worktime (17:00..21:00)', 'wc_makecommerce_domain' ) . '</option>
77 </select>
78 </p>
79 ';
80 }
81
82 return '
83 <tr style="display: none;" class="parcel_machine_checkout parcel_machine_checkout_courier_' . mb_strtolower($ext ) . '">
84 <th>'.__('Pick courier arrival time window', 'wc_makecommerce_domain').'</th>
85 <td>
86 <p class="form-row" id="' . esc_attr( $id ) . '_field">
87 <select class="select parcel-machine-select-box-time" name="' . esc_attr( $id ) . '" id="' . esc_attr( $id ) . '">
88 <option value="1">' . __( 'Any time', 'wc_makecommerce_domain' ) . '</option>
89 <option value="2">' . __( 'Worktime (09:00..17:00)', 'wc_makecommerce_domain' ) . '</option>
90 <option value="3">' . __( 'After worktime (17:00..21:00)', 'wc_makecommerce_domain' ) . '</option>
91 </select>
92 </p>
93 </td>
94 </tr>
95 ';
96 }
97
98 /**
99 * Adds delivery time option to order metadata
100 *
101 * @since 3.0.0
102 */
103 public function add_order_meta( $order_id ) {
104
105 if ( !empty( $_POST[$this->id] ) ) {
106 $order = wc_get_order( $order_id );
107 $order->update_meta_data( '_delivery_time', sanitize_text_field( $_POST[$this->id] ) );
108 $order->save();
109 }
110 }
111 }
112