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