css
4 months ago
img
4 months ago
js
4 months ago
partials
4 months ago
class-adv-order-filter.php
4 months ago
class-analytics.php
4 months ago
class-order-tip-promotion.php
4 months ago
class-pi-dtt-labels.php
4 months ago
class-pi-dtt-order-table.php
4 months ago
conflict-fixer.php
4 months ago
menu.php
4 months ago
options-addons.php
4 months ago
options-date.php
4 months ago
options-limit.php
4 months ago
options-pickup.php
4 months ago
options-time-slot.php
4 months ago
options-time.php
4 months ago
options.php
4 months ago
class-pi-dtt-order-table.php
209 lines
| 1 | <?php |
| 2 | if ( ! defined( 'ABSPATH' ) ) exit; |
| 3 | |
| 4 | if(!class_exists('pisol_dtt_order_table')){ |
| 5 | class pisol_dtt_order_table{ |
| 6 | function __construct(){ |
| 7 | add_filter( 'manage_edit-shop_order_columns', array($this,'deliverPickupDateColumn') ); |
| 8 | add_filter( 'manage_woocommerce_page_wc-orders_columns', array($this,'deliverPickupDateColumn') ); //hpos |
| 9 | |
| 10 | add_action( 'manage_shop_order_posts_custom_column', array($this,'deliverPickupDate') ); |
| 11 | add_action( 'manage_woocommerce_page_wc-orders_custom_column', array($this,'deliverPickupDateHPOS'),10, 2 ); //hpos |
| 12 | |
| 13 | add_filter( 'manage_edit-shop_order_sortable_columns', array($this,'sortByDate') ); |
| 14 | add_filter( 'woocommerce_shop_order_list_table_sortable_columns', array($this,'sortByDate') ); //hpos |
| 15 | add_filter( 'manage_woocommerce_page_wc-orders_sortable_columns', array($this,'sortByDate') );//hpos |
| 16 | |
| 17 | add_action( 'pre_get_posts', array($this,'sortByValue') ); |
| 18 | add_filter( 'woocommerce_shop_order_list_table_prepare_items_query_args', array($this, 'sortByValueHPOS') ); //hpos |
| 19 | } |
| 20 | |
| 21 | function sortByDate($col){ |
| 22 | $col['pisol_dpd'] = 'pisol_dpd'; |
| 23 | $col['pisol_method'] = 'pisol_method'; |
| 24 | $col['pisol_time'] = 'pisol_time'; |
| 25 | return $col; |
| 26 | } |
| 27 | |
| 28 | function sortByValue($query){ |
| 29 | if( ! is_admin() ) return; |
| 30 | |
| 31 | $orderby = $query->get( 'orderby'); |
| 32 | |
| 33 | if( 'pisol_dpd' == $orderby ) { |
| 34 | $query->set('meta_key','pi_system_delivery_date'); |
| 35 | $query->set('meta_type','DATE'); |
| 36 | $query->set('orderby','meta_value'); |
| 37 | } |
| 38 | |
| 39 | if( 'pisol_method' == $orderby ) { |
| 40 | $query->set('meta_key','pi_delivery_type'); |
| 41 | $query->set('orderby','meta_value'); |
| 42 | } |
| 43 | |
| 44 | if( 'pisol_time' == $orderby ) { |
| 45 | $query->set('meta_key','pi_delivery_time'); |
| 46 | $query->set('meta_type','TIME'); |
| 47 | $query->set('orderby','meta_value'); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * At present sorting is not working |
| 53 | */ |
| 54 | function sortByValueHPOS($args){ |
| 55 | if( ! is_admin() ) return $args; |
| 56 | |
| 57 | $orderby = isset($args[ 'orderby']) ? $args[ 'orderby'] : ''; |
| 58 | |
| 59 | if( 'pisol_dpd' == $orderby ) { |
| 60 | $args['orderby'] = 'meta_value'; |
| 61 | $args['meta_key'] = 'pi_system_delivery_date'; |
| 62 | $args['meta_type'] = 'DATE'; |
| 63 | } |
| 64 | |
| 65 | if( 'pisol_method' == $orderby ) { |
| 66 | $args['meta_key'] = 'pi_delivery_type'; |
| 67 | $args['orderby'] = 'meta_value'; |
| 68 | } |
| 69 | |
| 70 | if( 'pisol_time' == $orderby ) { |
| 71 | $args['orderby'] = 'meta_value'; |
| 72 | $args['meta_key'] = 'pi_delivery_time'; |
| 73 | $args['meta_type'] = 'TIME'; |
| 74 | } |
| 75 | |
| 76 | return $args; |
| 77 | } |
| 78 | |
| 79 | function deliverPickupDateColumn( $columns ) { |
| 80 | $columns['pisol_dpd'] = __('Order Arrival Date','pisol-dtt'); |
| 81 | $columns['pisol_time'] = __('Order Arrival Time','pisol-dtt'); |
| 82 | $columns['pisol_method'] = __('Method','pisol-dtt'); |
| 83 | $columns['pisol_pickup_location'] = __('Pickup shop','pisol-dtt'); |
| 84 | return $columns; |
| 85 | } |
| 86 | |
| 87 | function deliverPickupDate( $column ) { |
| 88 | global $post; |
| 89 | $order = wc_get_order( $post->ID ); |
| 90 | |
| 91 | if(empty($order)) return; |
| 92 | |
| 93 | if ( 'pisol_dpd' === $column ) { |
| 94 | $date = ""; |
| 95 | $sysdeldate = $order->get_meta( 'pi_system_delivery_date', true ); |
| 96 | $old_date = $order->get_meta( 'pi_delivery_date', true ); |
| 97 | |
| 98 | if(! empty($sysdeldate)){ |
| 99 | |
| 100 | $date = pi_dtt_date::translatedDate($sysdeldate); |
| 101 | echo wp_kses_post( $this->emptyValue($date) ); |
| 102 | |
| 103 | }elseif(!empty($old_date)){ |
| 104 | $date = ($old_date); |
| 105 | echo wp_kses_post( $date ); |
| 106 | } |
| 107 | |
| 108 | } |
| 109 | |
| 110 | if ( 'pisol_time' === $column ) { |
| 111 | $time = $order->get_meta( 'pi_delivery_time', true ); |
| 112 | echo wp_kses_post( pisol_dtt_time::formatTimeForDisplay($time) ); |
| 113 | } |
| 114 | |
| 115 | if ( 'pisol_method' === $column ) { |
| 116 | $delivery_method = $order->get_meta( 'pi_delivery_type', true ); |
| 117 | |
| 118 | if( $delivery_method =='pickup'){ |
| 119 | $order_delivery_type = __('Pickup','pisol-dtt'); |
| 120 | $class= "processing"; |
| 121 | }else{ |
| 122 | $order_delivery_type = __('Delivery','pisol-dtt'); |
| 123 | $class= "completed"; |
| 124 | } |
| 125 | $order_delivery_type = '<mark class="order-status status-'.$class.' "><span>'.$order_delivery_type.'</span></mark>'; |
| 126 | $order_delivery_type = apply_filters('pisol_dtt_order_table_delivery_method', $order_delivery_type, $delivery_method); |
| 127 | echo wp_kses_post( $this->emptyValue($order_delivery_type) ) ; |
| 128 | } |
| 129 | |
| 130 | if ( 'pisol_pickup_location' === $column ) { |
| 131 | $old_location = $order->get_meta( 'pickup_location', true ); |
| 132 | $location_id = $order->get_meta( 'pickup_location_id', true ); |
| 133 | |
| 134 | if(empty($location_id)){ |
| 135 | echo wp_kses_post( $old_location ); |
| 136 | }elseif(!empty($location_id)){ |
| 137 | $location_post = get_post($location_id); |
| 138 | $location_title = $location_post->post_title; |
| 139 | echo wp_kses_post( $location_title ); |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | function deliverPickupDateHPOS( $column, $order ) { |
| 145 | |
| 146 | if(empty($order)) return; |
| 147 | |
| 148 | if ( 'pisol_dpd' === $column ) { |
| 149 | $date = ""; |
| 150 | $sysdeldate = $order->get_meta('pi_system_delivery_date', true ); |
| 151 | $old_date = $order->get_meta( 'pi_delivery_date', true ); |
| 152 | |
| 153 | if(! empty($sysdeldate)){ |
| 154 | |
| 155 | $date = pi_dtt_date::translatedDate($sysdeldate); |
| 156 | echo wp_kses_post( $this->emptyValue($date) ); |
| 157 | |
| 158 | }elseif(!empty($old_date)){ |
| 159 | $date = ($old_date); |
| 160 | echo wp_kses_post( $date ); |
| 161 | } |
| 162 | |
| 163 | } |
| 164 | |
| 165 | if ( 'pisol_time' === $column ) { |
| 166 | $time = $order->get_meta( 'pi_delivery_time', true ); |
| 167 | echo wp_kses_post( pisol_dtt_time::formatTimeForDisplay($time) ); |
| 168 | } |
| 169 | |
| 170 | if ( 'pisol_method' === $column ) { |
| 171 | $delivery_method = $order->get_meta( 'pi_delivery_type', true ); |
| 172 | |
| 173 | if( $delivery_method =='pickup'){ |
| 174 | $order_delivery_type = __('Pickup','pisol-dtt'); |
| 175 | $class= "processing"; |
| 176 | }else{ |
| 177 | $order_delivery_type = __('Delivery','pisol-dtt'); |
| 178 | $class= "completed"; |
| 179 | } |
| 180 | $order_delivery_type = '<mark class="order-status status-'.$class.' "><span>'.$order_delivery_type.'</span></mark>'; |
| 181 | $order_delivery_type = apply_filters('pisol_dtt_order_table_delivery_method', $order_delivery_type, $delivery_method); |
| 182 | echo wp_kses_post( $this->emptyValue($order_delivery_type) ) ; |
| 183 | } |
| 184 | |
| 185 | if ( 'pisol_pickup_location' === $column ) { |
| 186 | $old_location = $order->get_meta( 'pickup_location', true ); |
| 187 | $location_id = $order->get_meta( 'pickup_location_id', true ); |
| 188 | |
| 189 | if(empty($location_id)){ |
| 190 | echo wp_kses_post( $old_location ); |
| 191 | }elseif(!empty($location_id)){ |
| 192 | $location_post = get_post($location_id); |
| 193 | $location_title = $location_post->post_title; |
| 194 | echo wp_kses_post( $location_title ); |
| 195 | } |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | function emptyValue($value){ |
| 200 | if($value != ""){ |
| 201 | return $value; |
| 202 | }else{ |
| 203 | return '-'; |
| 204 | } |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | new pisol_dtt_order_table(); |
| 209 | } |