PluginProbe ʕ •ᴥ•ʔ
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 2.13.0
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v2.13.0
4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.11.0 1.11.1 1.11.2 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.9.0 1.9.1 1.9.2 1.9.3 1.9.4 1.9.5 2.0.0 2.0.1 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.10.0 2.10.1 2.11.0 2.11.1 2.11.2 2.11.3 2.11.4 2.12.0 2.13.0 2.14.0 2.14.1 2.15.0 2.15.1 2.16.0 2.16.1 2.16.2 2.16.3 2.17.0 2.17.1 2.17.2 2.18.0 2.19.0 2.19.2 2.19.3 2.19.4 2.2.0 2.2.1 2.20.0 2.20.1 2.20.2 2.20.3 2.20.4 2.20.5 2.20.6 2.21.0 2.22.0 2.22.1 2.23.0 2.24.0 2.25.0 2.25.1 2.25.2 2.26.0 2.27.0 2.27.1 2.28.0 2.29.0 2.29.1 2.29.2 2.29.3 2.29.4 2.3.0 2.3.1 2.30.0 2.31.0 2.31.1 2.31.2 2.31.3 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.40.0 2.40.1 2.5.0 2.5.1 2.5.2 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.9.0 3.0.0 3.0.0-RC1 3.0.0-RC2 3.0.0-beta1 3.0.0-beta2 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.10.0 3.10.1 3.11.0 3.12.0 3.13.0 3.13.1 3.13.2 3.13.3 3.13.4 3.14.0 3.15.0 3.15.1 3.15.2 3.15.3 3.15.4 3.15.5 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.16.6 3.16.7 3.16.8 3.17.0 3.17.1 3.17.2 3.17.3 3.17.4 3.17.5 3.17.6 3.18.0 3.19.0 3.19.1 3.19.2 3.2.0 3.2.1 3.2.2 3.20.0 3.20.1 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 4.0.0 4.0.1 4.0.2 4.0.3 trunk 4.1.0 0.2.19.1 4.1.1 1.0.0 4.2.0 1.0.1 1.0.2
surecart / app / src / Controllers / Admin / Orders / OrdersListTable.php
surecart / app / src / Controllers / Admin / Orders Last commit date
OrderScriptsController.php 3 years ago OrdersListTable.php 2 years ago OrdersViewController.php 2 years ago
OrdersListTable.php
455 lines
1 <?php
2
3 namespace SureCart\Controllers\Admin\Orders;
4
5 use SureCart\Models\Order;
6 use SureCart\Controllers\Admin\Tables\ListTable;
7
8 /**
9 * Create a new table class that will extend the WP_List_Table
10 */
11 class OrdersListTable extends ListTable {
12 /**
13 * Prepare the items for the table to process
14 *
15 * @return Void
16 */
17 public function prepare_items() {
18 $columns = $this->get_columns();
19 $hidden = $this->get_hidden_columns();
20 $sortable = $this->get_sortable_columns();
21
22 $this->_column_headers = array( $columns, $hidden, $sortable );
23
24 $query = $this->table_data();
25 if ( is_wp_error( $query ) ) {
26 $this->items = [];
27 return;
28 }
29
30 $this->set_pagination_args(
31 [
32 'total_items' => $query->pagination->count,
33 'per_page' => $this->get_items_per_page( 'orders' ),
34 ]
35 );
36
37 $this->items = $query->data;
38 }
39
40 /**
41 * Show any integrations.
42 *
43 * @param \SureCart\Models\Order $order Order.
44 */
45 public function column_integrations( $order ) {
46 $output = '';
47
48 // loop through each purchase.
49 if ( ! empty( $order->checkout->purchases->data ) ) {
50 foreach ( $order->checkout->purchases->data as $purchase ) {
51 $output .= $this->productIntegrationsList( $purchase->product );
52 }
53 }
54
55 return $output ? $output : '-';
56 }
57
58 /**
59 * @global int $post_id
60 * @global string $comment_status
61 * @global string $comment_type
62 */
63 protected function get_views() {
64 $stati = [
65 'all' => __( 'All', 'surecart' ),
66 'paid' => __( 'Paid', 'surecart' ),
67 'processing' => __( 'Processing', 'surecart' ),
68 'payment_failed' => __( 'Failed', 'surecart' ),
69 'canceled' => __( 'Canceled', 'surecart' ),
70 ];
71
72 $link = \SureCart::getUrl()->index( 'orders' );
73
74 foreach ( $stati as $status => $label ) {
75 $current_link_attributes = '';
76
77 if ( ! empty( $_GET['status'] ) ) {
78 if ( $status === $_GET['status'] ) {
79 $current_link_attributes = ' class="current" aria-current="page"';
80 }
81 } elseif ( 'all' === $status ) {
82 $current_link_attributes = ' class="current" aria-current="page"';
83 }
84
85 $link = add_query_arg( 'status', $status, $link );
86
87 $status_links[ $status ] = "<a href='$link'$current_link_attributes>" . $label . '</a>';
88 }
89
90 // filter links.
91 return apply_filters( 'sc_order_status_links', $status_links );
92 }
93
94 /**
95 * Override the parent columns method. Defines the columns to use in your listing table
96 *
97 * @return array
98 */
99 public function get_columns() {
100
101 $columns = [
102 // 'cb' => '<input type="checkbox" />',
103 'order' => __( 'Order', 'surecart' ),
104 'status' => __( 'Status', 'surecart' ),
105 'fulfillment_status' => __( 'Fulfillment', 'surecart' ),
106 'shipment_status' => __( 'Shipping', 'surecart' ),
107 'method' => __( 'Method', 'surecart' ),
108 'integrations' => __( 'Integrations', 'surecart' ),
109 'total' => __( 'Total', 'surecart' ),
110 'type' => __( 'Type', 'surecart' ),
111 'created' => __( 'Date', 'surecart' ),
112 'mode' => '',
113 ];
114
115 return $columns;
116 }
117
118 /**
119 * Displays the checkbox column.
120 *
121 * @param Product $product The product model.
122 */
123 public function column_cb( $product ) {
124 ?>
125 <label class="screen-reader-text" for="cb-select-<?php echo esc_attr( $product['id'] ); ?>"><?php _e( 'Select comment', 'surecart' ); ?></label>
126 <input id="cb-select-<?php echo esc_attr( $product['id'] ); ?>" type="checkbox" name="delete_comments[]" value="<?php echo esc_attr( $product['id'] ); ?>" />
127 <?php
128 }
129
130 /**
131 * Define which columns are hidden
132 *
133 * @return Array
134 */
135 public function get_hidden_columns() {
136 return ( is_array( get_user_meta( get_current_user_id(), 'managesurecart_page_sc-orderscolumnshidden', true ) ) ) ? get_user_meta( get_current_user_id(), 'managesurecart_page_sc-orderscolumnshidden', true ) : array();
137 }
138
139 /**
140 * Define the sortable columns
141 *
142 * @return Array
143 */
144 public function get_sortable_columns() {
145 return array( 'title' => array( 'title', false ) );
146 }
147
148 /**
149 * Get the table data
150 *
151 * @return Array
152 */
153 protected function table_data() {
154 return Order::where(
155 [
156 'status' => $this->getStatus(),
157 'fulfillment_status' => ! empty( $_GET['fulfillment_status'] ) ? [ $_GET['fulfillment_status'] ] : [],
158 'shipment_status' => ! empty( $_GET['shipment_status'] ) ? [ $_GET['shipment_status'] ] : [],
159 'query' => $this->get_search_query(),
160 ]
161 )->with( [ 'checkout', 'checkout.charge', 'checkout.customer', 'checkout.payment_method', 'checkout.manual_payment_method', 'checkout.purchases', 'payment_method.card', 'payment_method.payment_instrument', 'payment_method.paypal_account', 'payment_method.bank_account' ] )
162 ->paginate(
163 [
164 'per_page' => $this->get_items_per_page( 'orders' ),
165 'page' => $this->get_pagenum(),
166 ]
167 );
168 }
169
170 /**
171 * Get the archive query status.
172 *
173 * @return boolean|null
174 */
175 public function getStatus() {
176 $status = sanitize_text_field( wp_unslash( $_GET['status'] ?? 'all' ) );
177 if ( 'paid' === $status ) {
178 return [ 'paid' ];
179 }
180 if ( 'payment_failed' === $status ) {
181 return [ 'payment_failed' ];
182 }
183 if ( 'processing' === $status ) {
184 return [ 'processing' ];
185 }
186 if ( 'canceled' === $status ) {
187 return [ 'canceled' ];
188 }
189 if ( 'all' === $status ) {
190 return [];
191 }
192 return $status ? [ esc_html( $status ) ] : [];
193 }
194
195 /**
196 * Handle the total column
197 *
198 * @param \SureCart\Models\Order $order The order model.
199 *
200 * @return string
201 */
202 public function column_total( $order ) {
203 return '<sc-format-number type="currency" currency="' . strtoupper( esc_html( $order->checkout->currency ) ) . '" value="' . (float) $order->checkout->amount_due . '"></sc-format-number>';
204 }
205
206 /**
207 * Show the payment method for the order.
208 *
209 * @param \SureCart\Models\Order $order The order model.
210 *
211 * @return string
212 */
213 public function column_method( $order ) {
214 if ( isset( $order->checkout->manual_payment_method->name ) ) {
215 return '<sc-tag>' . $order->checkout->manual_payment_method->name . '</sc-tag>';
216 }
217 ob_start();
218 ?>
219 <sc-payment-method id="sc-method-<?php echo esc_attr( $order->id ); ?>"></sc-payment-method>
220 <script>
221 document.getElementById('sc-method-<?php echo esc_attr( $order->id ); ?>').paymentMethod = <?php echo wp_json_encode( $order->checkout->payment_method ); ?>;
222 </script>
223 <?php
224 return ob_get_clean();
225 }
226
227 /**
228 * The type of order.
229 *
230 * @param \SureCart\Models\Order $order The order model.
231 *
232 * @return string
233 */
234 public function column_type( $order ) {
235 if ( ! empty( $order->order_type ) && 'subscription' === $order->order_type ) {
236 return '<sc-tag type="success">' . esc_html__( 'Plan Renewal', 'surecart' ) . '</sc-tag>';
237 }
238
239 return '<sc-tag type="info">' . esc_html__( 'Checkout', 'surecart' ) . '</sc-tag>';
240 }
241
242 /**
243 * Handle the status
244 *
245 * @param \SureCart\Models\Order $order Order Model.
246 *
247 * @return string
248 */
249 public function column_status( $order ) {
250 if ( ! empty( $order->checkout->charge->fully_refunded ) ) {
251 return '<sc-tag type="danger">' . __( 'Refunded', 'surecart' ) . '</sc-tag>';
252 }
253
254 if ( ! empty( $order->checkout->payment_method->processor_type ) && 'paypal' === $order->checkout->payment_method->processor_type ) {
255 if ( 'requires_approval' === $order->status ) {
256 return '<sc-tooltip text="' . __( 'Paypal is taking a closer look at this payment. It’s required for some payments and normally takes up to 3 business days.', 'surecart' ) . '" type="warning"><sc-order-status-badge status="' . esc_attr( $order->status ) . '"></sc-order-status-badge></sc-tooltip>';
257 }
258 }
259
260 return '<sc-order-status-badge status="' . esc_attr( $order->status ) . '"></sc-order-status-badge>';
261 }
262
263 /**
264 * Handle the status
265 *
266 * @param \SureCart\Models\Order $order Order Model.
267 *
268 * @return string
269 */
270 public function column_fulfillment_status( $order ) {
271 ob_start();
272 ?>
273 <sc-order-fulfillment-badge status="<?php echo esc_attr( $order->fulfillment_status ); ?>"></sc-order-fulfillment-badge>
274 <?php
275 return ob_get_clean();
276 }
277
278 /**
279 * Handle the status
280 *
281 * @param \SureCart\Models\Order $order Order Model.
282 *
283 * @return string
284 */
285 public function column_shipment_status( $order ) {
286 ob_start();
287 ?>
288 <?php if ( 'unshippable' === $order->shipment_status ) : ?>
289 -
290 <?php else : ?>
291 <sc-order-shipment-badge status="<?php echo esc_attr( $order->shipment_status ); ?>"></sc-order-shipment-badge>
292 <?php endif; ?>
293 <?php
294 return ob_get_clean();
295 }
296
297 /**
298 * Name of the coupon
299 *
300 * @param \SureCart\Models\Promotion $promotion Promotion model.
301 *
302 * @return string
303 */
304 public function column_order( $order ) {
305 ob_start();
306 ?>
307 <a class="row-title" aria-label="<?php echo esc_attr__( 'Edit Order', 'surecart' ); ?>" href="<?php echo esc_url( \SureCart::getUrl()->edit( 'order', $order->id ) ); ?>">
308 #<?php echo sanitize_text_field( $order->number ?? $order->id ); ?>
309 </a>
310 <br />
311 <a aria-label="<?php echo esc_attr__( 'Edit Order', 'surecart' ); ?>" href="<?php echo esc_url( \SureCart::getUrl()->edit( 'order', $order->id ) ); ?>" style="word-break: break-word">
312 <?php
313 // translators: Customer name.
314 echo sprintf( esc_html__( 'By %s', 'surecart' ), esc_html( $order->checkout->customer->name ?? $order->checkout->customer->email ) );
315 ?>
316 </a>
317 <?php
318
319 return ob_get_clean();
320 }
321
322 /**
323 * Displays a formats drop-down for filtering items.
324 *
325 * @since 5.2.0
326 * @access protected
327 *
328 * @param string $post_type Post type slug.
329 */
330 protected function fulfillment_dropdown() {
331 /**
332 * Filters whether to remove the 'Formats' drop-down from the post list table.
333 *
334 * @param bool $disable Whether to disable the drop-down. Default false.
335 */
336 if ( apply_filters( 'surecart/disable_fulfillment_dropdown', false ) ) {
337 return;
338 }
339
340 $displayed_order_fulfillment = isset( $_GET['fulfillment_status'] ) ? $_GET['fulfillment_status'] : '';
341 ?>
342
343 <label for="filter-by-fulfillment" class="screen-reader-text">
344 <?php
345 /* translators: Hidden accessibility text. */
346 esc_html_e( 'Filter by fulfillment', 'surecart' );
347 ?>
348 </label>
349 <select name="fulfillment_status" id="filter-by-fulfillment">
350 <option<?php selected( $displayed_order_fulfillment, '' ); ?> value=""><?php esc_html_e( 'All Fulfillments', 'surecart' ); ?></option>
351 <option<?php selected( $displayed_order_fulfillment, 'unfulfilled' ); ?> value="unfulfilled"><?php echo esc_html_e( 'Unfulfilled', 'surecart' ); ?></option>
352 <option<?php selected( $displayed_order_fulfillment, 'fulfilled' ); ?> value="fulfilled"><?php echo esc_html_e( 'Fulfilled', 'surecart' ); ?></option>
353 <option<?php selected( $displayed_order_fulfillment, '"partially_fulfilled' ); ?> value="fulfilled"><?php echo esc_html_e( 'Partially Fulfilled', 'surecart' ); ?></option>
354 </select>
355 <?php
356 }
357
358 /**
359 * Displays a formats drop-down for filtering items.
360 *
361 * @since 5.2.0
362 * @access protected
363 *
364 * @param string $post_type Post type slug.
365 */
366 protected function shipment_dropdown() {
367 /**
368 * Filters whether to remove the 'Formats' drop-down from the post list table.
369 *
370 * @param bool $disable Whether to disable the drop-down. Default false.
371 */
372 if ( apply_filters( 'surecart/disable_shipment_dropdown', false ) ) {
373 return;
374 }
375
376 $displayed_order_shipment = isset( $_GET['shipment_status'] ) ? $_GET['shipment_status'] : '';
377 ?>
378
379 <label for="filter-by-shipment" class="screen-reader-text">
380 <?php
381 /* translators: Hidden accessibility text. */
382 esc_html_e( 'Filter by shipment', 'surecart' );
383 ?>
384 </label>
385 <select name="shipment_status" id="filter-by-shipment">
386 <option<?php selected( $displayed_order_shipment, '' ); ?> value=""><?php esc_html_e( 'All Shipment Statuses', 'surecart' ); ?></option>
387 <option<?php selected( $displayed_order_shipment, 'unshipped' ); ?> value="unshipped"><?php echo esc_html_e( 'Not Shipped', 'surecart' ); ?></option>
388 <option<?php selected( $displayed_order_shipment, 'shipped' ); ?> value="shipped"><?php echo esc_html_e( 'Shipped', 'surecart' ); ?></option>
389 <option<?php selected( $displayed_order_shipment, 'partially_shipped' ); ?> value="partially_shipped"><?php echo esc_html_e( 'Partially Shipped', 'surecart' ); ?></option>
390 <option<?php selected( $displayed_order_shipment, 'delivered' ); ?> value="delivered"><?php echo esc_html_e( 'Delivered', 'surecart' ); ?></option>
391 </select>
392 <?php
393 }
394
395 /**
396 * Displays extra table navigation.
397 *
398 * @param string $which Top or bottom placement.
399 */
400 protected function extra_tablenav( $which ) {
401 ?>
402 <input type="hidden" name="page" value="sc-orders" />
403
404 <?php if ( ! empty( $_GET['status'] ) ) : ?>
405 <input type="hidden" name="status" value="<?php echo esc_attr( $_GET['status'] ); ?>" />
406 <?php endif; ?>
407
408 <div class="alignleft actions">
409 <?php
410 if ( 'top' === $which ) {
411 ob_start();
412 $this->fulfillment_dropdown();
413 $this->shipment_dropdown();
414
415 /**
416 * Fires before the Filter button on the Posts and Pages list tables.
417 *
418 * The Filter button allows sorting by date and/or category on the
419 * Posts list table, and sorting by date on the Pages list table.
420 *
421 * @since 2.1.0
422 * @since 4.4.0 The `$post_type` parameter was added.
423 * @since 4.6.0 The `$which` parameter was added.
424 *
425 * @param string $post_type The post type slug.
426 * @param string $which The location of the extra table nav markup:
427 * 'top' or 'bottom' for WP_Posts_List_Table,
428 * 'bar' for WP_Media_List_Table.
429 */
430 do_action( 'restrict_manage_orders', $this->screen->post_type, $which );
431
432 $output = ob_get_clean();
433
434 if ( ! empty( $output ) ) {
435 echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
436 submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'filter-by-fulfillment-submit' ) );
437 }
438 }
439
440 ?>
441 </div>
442
443 <?php
444 /**
445 * Fires immediately following the closing "actions" div in the tablenav for the posts
446 * list table.
447 *
448 * @since 4.4.0
449 *
450 * @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
451 */
452 do_action( 'manage_orders_extra_tablenav', $which );
453 }
454 }
455