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