css
2 years ago
js
2 years ago
class-css.php
2 years ago
class-date.php
2 years ago
class-delivery-type.php
2 years ago
class-display-field.php
2 years ago
class-js.php
2 years ago
class-main.php
2 years ago
class-order.php
2 years ago
class-pickup-location.php
2 years ago
class-shipping-method.php
2 years ago
class-time-range.php
2 years ago
class-time-slot.php
2 years ago
class-time.php
2 years ago
class-validate.php
2 years ago
class-woo-app.php
2 years ago
class-woo-app.php
61 lines
| 1 | <?php |
| 2 | |
| 3 | class pisol_dtt_woo_mobile_app_support{ |
| 4 | |
| 5 | protected $post_type = 'shop_order'; |
| 6 | |
| 7 | function __construct(){ |
| 8 | $add_to_order_note = pisol_dtt_get_setting('pi_enable_woocommerce_app_support', 0); |
| 9 | |
| 10 | if(empty($add_to_order_note)) return; |
| 11 | |
| 12 | add_action( 'woocommerce_checkout_update_order_meta', [$this,'addDataInNote'], PHP_INT_MAX, 1 ); |
| 13 | |
| 14 | add_action( 'save_post', array($this,'savePostTimeSlot'), PHP_INT_MAX, 2 ); |
| 15 | } |
| 16 | |
| 17 | function savePostTimeSlot( $post_id, $post ){ |
| 18 | |
| 19 | if(!apply_filters( 'pisol_dtt_order_note_on_edit', true )) return; |
| 20 | |
| 21 | if ( ( empty( $post_id ) || empty( $post ) || ( $this->post_type !== get_post_type( $post ) ) ) |
| 22 | || ( empty( $_POST['post_ID'] ) || $_POST['post_ID'] != $post_id ) |
| 23 | || ( ! current_user_can( 'edit_post', $post_id ) ) ) { |
| 24 | return; |
| 25 | } |
| 26 | |
| 27 | |
| 28 | $this->addDataInNote( $post_id ); |
| 29 | } |
| 30 | |
| 31 | function addDataInNote( $order_id ){ |
| 32 | $order = wc_get_order($order_id); |
| 33 | |
| 34 | $type = $order->get_meta( 'pi_delivery_type', true ); // delivery type 'delivery' or 'pickup' |
| 35 | |
| 36 | $date = $order->get_meta( 'pi_system_delivery_date', true ); // date in yyyy/mm/dd format |
| 37 | if(class_exists('pi_dtt_date')){ |
| 38 | $date = pi_dtt_date::translatedDate($date); |
| 39 | } |
| 40 | |
| 41 | $time = $order->get_meta( 'pi_delivery_time', true ); // delivery time |
| 42 | if(class_exists("pisol_dtt_time")){ |
| 43 | $time = pisol_dtt_time::formatTimeForDisplay($time); |
| 44 | } |
| 45 | |
| 46 | $location = $order->get_meta( 'pickup_location', true ); // pickup location |
| 47 | |
| 48 | $note = __('Delivery Type:', 'pisol-dtt').' '.$type; |
| 49 | $note .= '<br>'.__('Data:','pisol-dtt').' '.$date; |
| 50 | $note .= '<br>'.__('Time:','pisol-dtt').' '.$time; |
| 51 | if(!empty($location)){ |
| 52 | $note .= '<br>'.__('Location:','pisol-dtt').' '.$location; |
| 53 | } |
| 54 | |
| 55 | $note = apply_filters('pisol_dtt_order_note_filter', $note, $order); |
| 56 | |
| 57 | $order->add_order_note( $note ); |
| 58 | } |
| 59 | |
| 60 | } |
| 61 | new pisol_dtt_woo_mobile_app_support(); |