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