PluginProbe ʕ •ᴥ•ʔ
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 3.0.3
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v3.0.3
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 1 year ago OrdersViewController.php 1 year ago
OrdersListTable.php
483 lines
1 <?php
2
3 namespace SureCart\Controllers\Admin\Orders;
4
5 use SureCart\Models\Order;
6 use SureCart\Controllers\Admin\Tables\ListTable;
7 use SureCart\Controllers\Admin\Tables\HasModeFilter;
8
9 /**
10 * Create a new table class that will extend the WP_List_Table
11 */
12 class OrdersListTable extends ListTable {
13 use HasModeFilter;
14
15 /**
16 * Prepare the items for the table to process
17 *
18 * @return Void
19 */
20 public function prepare_items() {
21 $columns = $this->get_columns();
22 $hidden = $this->get_hidden_columns();
23 $sortable = $this->get_sortable_columns();
24
25 $this->_column_headers = array( $columns, $hidden, $sortable );
26
27 $query = $this->table_data();
28 if ( is_wp_error( $query ) ) {
29 $this->items = [];
30 return;
31 }
32
33 $this->set_pagination_args(
34 [
35 'total_items' => $query->pagination->count,
36 'per_page' => $this->get_items_per_page( 'orders' ),
37 ]
38 );
39
40 $this->items = $query->data;
41 }
42
43 /**
44 * Show any integrations.
45 *
46 * @param \SureCart\Models\Order $order Order.
47 */
48 public function column_integrations( $order ) {
49 $output = '';
50
51 // loop through each purchase.
52 if ( ! empty( $order->checkout->purchases->data ) ) {
53 foreach ( $order->checkout->purchases->data as $purchase ) {
54 // TODO: eager load this to prevent n+1 queries.
55 $output .= $this->productIntegrationsList(
56 [
57 'product_id' => $purchase->product,
58 'price_id' => $purchase->price->id ?? $purchase->price ?? null,
59 'variant_id' => $purchase->variant->id ?? $purchase->variant ?? null,
60 ]
61 );
62 }
63 }
64
65 return $output ? $output : '-';
66 }
67
68 /**
69 * @global int $post_id
70 * @global string $comment_status
71 * @global string $comment_type
72 */
73 protected function get_views() {
74 $stati = [
75 'all' => __( 'All', 'surecart' ),
76 'paid' => __( 'Paid', 'surecart' ),
77 'processing' => __( 'Processing', 'surecart' ),
78 'draft' => __( 'Draft', 'surecart' ),
79 'payment_failed' => __( 'Failed', 'surecart' ),
80 'canceled' => __( 'Canceled', 'surecart' ),
81 ];
82
83 foreach ( $stati as $status => $label ) {
84 $link = \SureCart::getUrl()->index( 'orders' );
85 $current_link_attributes = '';
86
87 if ( ! empty( $_GET['status'] ) ) {
88 if ( $status === $_GET['status'] ) {
89 $current_link_attributes = ' class="current" aria-current="page"';
90 }
91 } elseif ( 'all' === $status ) {
92 $current_link_attributes = ' class="current" aria-current="page"';
93 }
94
95 $link = add_query_arg( 'status', $status, $link );
96
97 $link = esc_url( $link );
98
99 $status_links[ $status ] = "<a href='$link'$current_link_attributes>" . $label . '</a>';
100 }
101
102 // filter links.
103 return apply_filters( 'sc_order_status_links', $status_links );
104 }
105
106 /**
107 * Override the parent columns method. Defines the columns to use in your listing table
108 *
109 * @return array
110 */
111 public function get_columns() {
112
113 $columns = [
114 // 'cb' => '<input type="checkbox" />',
115 'order' => __( 'Order', 'surecart' ),
116 'status' => __( 'Status', 'surecart' ),
117 'fulfillment_status' => __( 'Fulfillment', 'surecart' ),
118 'shipment_status' => __( 'Shipping', 'surecart' ),
119 'method' => __( 'Method', 'surecart' ),
120 'integrations' => __( 'Integrations', 'surecart' ),
121 'total' => __( 'Total', 'surecart' ),
122 'type' => __( 'Type', 'surecart' ),
123 'created' => __( 'Date', 'surecart' ),
124 'mode' => '',
125 ];
126
127 return $columns;
128 }
129
130 /**
131 * Displays the checkbox column.
132 *
133 * @param Product $product The product model.
134 */
135 public function column_cb( $product ) {
136 ?>
137 <label class="screen-reader-text" for="cb-select-<?php echo esc_attr( $product['id'] ); ?>"><?php _e( 'Select comment', 'surecart' ); ?></label>
138 <input id="cb-select-<?php echo esc_attr( $product['id'] ); ?>" type="checkbox" name="delete_comments[]" value="<?php echo esc_attr( $product['id'] ); ?>" />
139 <?php
140 }
141
142 /**
143 * Define which columns are hidden
144 *
145 * @return Array
146 */
147 public function get_hidden_columns() {
148 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();
149 }
150
151 /**
152 * Define the sortable columns
153 *
154 * @return Array
155 */
156 public function get_sortable_columns() {
157 return array( 'title' => array( 'title', false ) );
158 }
159
160 /**
161 * Get the table data
162 *
163 * @return Array
164 */
165 protected function table_data() {
166 $mode = sanitize_text_field( wp_unslash( $_GET['mode'] ?? '' ) );
167
168 $conditions = [
169 'status' => $this->getStatus(),
170 'fulfillment_status' => ! empty( $_GET['fulfillment_status'] ) ? [ $_GET['fulfillment_status'] ] : [],
171 'shipment_status' => ! empty( $_GET['shipment_status'] ) ? [ $_GET['shipment_status'] ] : [],
172 'query' => $this->get_search_query(),
173 ];
174
175 if ( ! empty( $mode ) ) {
176 $conditions['live_mode'] = 'live' === $mode;
177 }
178
179 return Order::where( $conditions )
180 ->with( [ 'checkout', 'checkout.charge', 'checkout.customer', 'checkout.payment_method', 'checkout.manual_payment_method', 'checkout.purchases', 'checkout.selected_shipping_choice', 'shipping_choice.shipping_method', 'payment_method.card', 'payment_method.payment_instrument', 'payment_method.paypal_account', 'payment_method.bank_account' ] )
181 ->paginate(
182 [
183 'per_page' => $this->get_items_per_page( 'orders' ),
184 'page' => $this->get_pagenum(),
185 ]
186 );
187 }
188
189 /**
190 * Get the archive query status.
191 *
192 * @return boolean|null
193 */
194 public function getStatus() {
195 $status = sanitize_text_field( wp_unslash( $_GET['status'] ?? 'all' ) );
196 if ( 'paid' === $status ) {
197 return [ 'paid' ];
198 }
199 if ( 'payment_failed' === $status ) {
200 return [ 'payment_failed' ];
201 }
202 if ( 'processing' === $status ) {
203 return [ 'processing' ];
204 }
205 if ( 'canceled' === $status ) {
206 return [ 'void' ];
207 }
208 if ( 'draft' === $status ) {
209 return [ 'draft' ];
210 }
211 if ( 'all' === $status ) {
212 return [];
213 }
214 return $status ? [ esc_html( $status ) ] : [];
215 }
216
217 /**
218 * Handle the total column
219 *
220 * @param \SureCart\Models\Order $order The order model.
221 *
222 * @return string
223 */
224 public function column_total( $order ) {
225 return '<sc-format-number type="currency" currency="' . strtoupper( esc_html( $order->checkout->currency ) ) . '" value="' . (float) $order->checkout->amount_due . '"></sc-format-number>';
226 }
227
228 /**
229 * Show the payment method for the order.
230 *
231 * @param \SureCart\Models\Order $order The order model.
232 *
233 * @return string
234 */
235 public function column_method( $order ) {
236 if ( isset( $order->checkout->manual_payment_method->name ) ) {
237 return '<sc-tag>' . $order->checkout->manual_payment_method->name . '</sc-tag>';
238 }
239 ob_start();
240 ?>
241 <sc-payment-method id="sc-method-<?php echo esc_attr( $order->id ); ?>"></sc-payment-method>
242 <script>
243 document.getElementById('sc-method-<?php echo esc_attr( $order->id ); ?>').paymentMethod = <?php echo wp_json_encode( $order->checkout->payment_method ); ?>;
244 </script>
245 <?php
246 return ob_get_clean();
247 }
248
249 /**
250 * The type of order.
251 *
252 * @param \SureCart\Models\Order $order The order model.
253 *
254 * @return string
255 */
256 public function column_type( $order ) {
257 if ( ! empty( $order->order_type ) && 'subscription' === $order->order_type ) {
258 return '<sc-tag type="success">' . esc_html__( 'Subscription', 'surecart' ) . '</sc-tag>';
259 }
260
261 return '<sc-tag type="info">' . esc_html__( 'Checkout', 'surecart' ) . '</sc-tag>';
262 }
263
264 /**
265 * Handle the status
266 *
267 * @param \SureCart\Models\Order $order Order Model.
268 *
269 * @return string
270 */
271 public function column_status( $order ) {
272 if ( ! empty( $order->checkout->charge->fully_refunded ) ) {
273 return '<sc-tag type="danger">' . __( 'Refunded', 'surecart' ) . '</sc-tag>';
274 }
275
276 if ( ! empty( $order->checkout->payment_method->processor_type ) && 'paypal' === $order->checkout->payment_method->processor_type ) {
277 if ( 'requires_approval' === $order->status ) {
278 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>';
279 }
280 }
281
282 return '<sc-order-status-badge status="' . esc_attr( $order->status ) . '"></sc-order-status-badge>';
283 }
284
285 /**
286 * Handle the status
287 *
288 * @param \SureCart\Models\Order $order Order Model.
289 *
290 * @return string
291 */
292 public function column_fulfillment_status( $order ) {
293 ob_start();
294 ?>
295 <sc-order-fulfillment-badge status="<?php echo esc_attr( $order->fulfillment_status ); ?>"></sc-order-fulfillment-badge>
296 <?php
297 return ob_get_clean();
298 }
299
300 /**
301 * Handle the status
302 *
303 * @param \SureCart\Models\Order $order Order Model.
304 *
305 * @return string
306 */
307 public function column_shipment_status( $order ) {
308 $shipping_method_name = ! empty( $order->checkout->selected_shipping_choice->shipping_method->name ) ? $order->checkout->selected_shipping_choice->shipping_method->name : false;
309
310 ob_start();
311 ?>
312 <?php if ( 'unshippable' === $order->shipment_status ) : ?>
313 -
314 <?php else : ?>
315 <sc-order-shipment-badge status="<?php echo esc_attr( $order->shipment_status ); ?>"></sc-order-shipment-badge>
316 <?php if ( $shipping_method_name ) : ?>
317 <div><small>(<?php echo esc_attr( $shipping_method_name ); ?>)</small></div>
318 <?php endif; ?>
319 <?php endif; ?>
320 <?php
321 return ob_get_clean();
322 }
323
324 /**
325 * Name of the coupon
326 *
327 * @param \SureCart\Models\Promotion $promotion Promotion model.
328 *
329 * @return string
330 */
331 public function column_order( $order ) {
332 ob_start();
333 ?>
334 <a class="row-title" aria-label="<?php esc_attr_e( 'Edit Order', 'surecart' ); ?>" href="<?php echo esc_url( \SureCart::getUrl()->edit( 'order', $order->id ) ); ?>">
335 #<?php echo sanitize_text_field( $order->number ?? $order->id ); ?>
336 </a>
337 <br />
338 <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">
339 <?php
340 // translators: Customer name.
341 printf( esc_html__( 'By %s', 'surecart' ), esc_html( $order->checkout->name ?? $order->checkout->email ?? $order->checkout->customer->name ?? $order->checkout->customer->email ) );
342 ?>
343 </a>
344 <?php
345
346 return ob_get_clean();
347 }
348
349 /**
350 * Displays a formats drop-down for filtering items.
351 *
352 * @since 5.2.0
353 * @access protected
354 *
355 * @param string $post_type Post type slug.
356 */
357 protected function fulfillment_dropdown() {
358 /**
359 * Filters whether to remove the 'Formats' drop-down from the post list table.
360 *
361 * @param bool $disable Whether to disable the drop-down. Default false.
362 */
363 if ( apply_filters( 'surecart/disable_fulfillment_dropdown', false ) ) {
364 return;
365 }
366
367 $displayed_order_fulfillment = isset( $_GET['fulfillment_status'] ) ? $_GET['fulfillment_status'] : '';
368 ?>
369
370 <label for="filter-by-fulfillment" class="screen-reader-text">
371 <?php
372 /* translators: Hidden accessibility text. */
373 esc_html_e( 'Filter by fulfillment', 'surecart' );
374 ?>
375 </label>
376 <select name="fulfillment_status" id="filter-by-fulfillment">
377 <option<?php selected( $displayed_order_fulfillment, '' ); ?> value=""><?php esc_html_e( 'All Fulfillments', 'surecart' ); ?></option>
378 <option<?php selected( $displayed_order_fulfillment, 'unfulfilled' ); ?> value="unfulfilled"><?php echo esc_html_e( 'Unfulfilled', 'surecart' ); ?></option>
379 <option<?php selected( $displayed_order_fulfillment, 'fulfilled' ); ?> value="fulfilled"><?php echo esc_html_e( 'Fulfilled', 'surecart' ); ?></option>
380 <option<?php selected( $displayed_order_fulfillment, '"partially_fulfilled' ); ?> value="fulfilled"><?php echo esc_html_e( 'Partially Fulfilled', 'surecart' ); ?></option>
381 </select>
382 <?php
383 }
384
385 /**
386 * Displays a formats drop-down for filtering items.
387 *
388 * @since 5.2.0
389 * @access protected
390 *
391 * @param string $post_type Post type slug.
392 */
393 protected function shipment_dropdown() {
394 /**
395 * Filters whether to remove the 'Formats' drop-down from the post list table.
396 *
397 * @param bool $disable Whether to disable the drop-down. Default false.
398 */
399 if ( apply_filters( 'surecart/disable_shipment_dropdown', false ) ) {
400 return;
401 }
402
403 $displayed_order_shipment = isset( $_GET['shipment_status'] ) ? $_GET['shipment_status'] : '';
404 ?>
405
406 <label for="filter-by-shipment" class="screen-reader-text">
407 <?php
408 /* translators: Hidden accessibility text. */
409 esc_html_e( 'Filter by shipment', 'surecart' );
410 ?>
411 </label>
412 <select name="shipment_status" id="filter-by-shipment">
413 <option<?php selected( $displayed_order_shipment, '' ); ?> value=""><?php esc_html_e( 'All Shipment Statuses', 'surecart' ); ?></option>
414 <option<?php selected( $displayed_order_shipment, 'unshipped' ); ?> value="unshipped"><?php echo esc_html_e( 'Not Shipped', 'surecart' ); ?></option>
415 <option<?php selected( $displayed_order_shipment, 'shipped' ); ?> value="shipped"><?php echo esc_html_e( 'Shipped', 'surecart' ); ?></option>
416 <option<?php selected( $displayed_order_shipment, 'partially_shipped' ); ?> value="partially_shipped"><?php echo esc_html_e( 'Partially Shipped', 'surecart' ); ?></option>
417 <option<?php selected( $displayed_order_shipment, 'delivered' ); ?> value="delivered"><?php echo esc_html_e( 'Delivered', 'surecart' ); ?></option>
418 </select>
419 <?php
420 }
421
422 /**
423 * Displays extra table navigation.
424 *
425 * @param string $which Top or bottom placement.
426 */
427 protected function extra_tablenav( $which ) {
428 ?>
429 <input type="hidden" name="page" value="sc-orders" />
430
431 <?php if ( ! empty( $_GET['status'] ) ) : ?>
432 <input type="hidden" name="status" value="<?php echo esc_attr( $_GET['status'] ); ?>" />
433 <?php endif; ?>
434
435 <div class="alignleft actions">
436 <?php
437 if ( 'top' === $which ) {
438 ob_start();
439 $this->fulfillment_dropdown();
440 $this->shipment_dropdown();
441 $this->mode_dropdown();
442
443 /**
444 * Fires before the Filter button on the Posts and Pages list tables.
445 *
446 * The Filter button allows sorting by date and/or category on the
447 * Posts list table, and sorting by date on the Pages list table.
448 *
449 * @since 2.1.0
450 * @since 4.4.0 The `$post_type` parameter was added.
451 * @since 4.6.0 The `$which` parameter was added.
452 *
453 * @param string $post_type The post type slug.
454 * @param string $which The location of the extra table nav markup:
455 * 'top' or 'bottom' for WP_Posts_List_Table,
456 * 'bar' for WP_Media_List_Table.
457 */
458 do_action( 'restrict_manage_orders', $this->screen->post_type, $which );
459
460 $output = ob_get_clean();
461
462 if ( ! empty( $output ) ) {
463 echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
464 submit_button( __( 'Filter', 'surecart' ), '', 'filter_action', false, array( 'id' => 'filter-by-fulfillment-submit' ) );
465 }
466 }
467
468 ?>
469 </div>
470
471 <?php
472 /**
473 * Fires immediately following the closing "actions" div in the tablenav for the posts
474 * list table.
475 *
476 * @since 4.4.0
477 *
478 * @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
479 */
480 do_action( 'manage_orders_extra_tablenav', $which );
481 }
482 }
483