get_columns(); $hidden = $this->get_hidden_columns(); $sortable = $this->get_sortable_columns(); $this->_column_headers = array( $columns, $hidden, $sortable ); $query = $this->table_data(); if ( is_wp_error( $query ) ) { $this->items = []; return; } $this->set_pagination_args( [ 'total_items' => $query->pagination->count, 'per_page' => $this->get_items_per_page( 'orders' ), ] ); $this->items = $query->data; } /** * Show any integrations. * * @param \SureCart\Models\Order $order Order. */ public function column_integrations( $order ) { $output = ''; // loop through each purchase. if ( ! empty( $order->checkout->purchases->data ) ) { foreach ( $order->checkout->purchases->data as $purchase ) { // TODO: eager load this to prevent n+1 queries. $output .= $this->productIntegrationsList( [ 'product_id' => $purchase->product, 'price_id' => $purchase->price->id ?? $purchase->price ?? null, 'variant_id' => $purchase->variant->id ?? $purchase->variant ?? null, ] ); } } return $output ? $output : '-'; } /** * @global int $post_id * @global string $comment_status * @global string $comment_type */ protected function get_views() { $stati = [ 'all' => __( 'All', 'surecart' ), 'paid' => __( 'Paid', 'surecart' ), 'processing' => __( 'Processing', 'surecart' ), 'draft' => __( 'Draft', 'surecart' ), 'payment_failed' => __( 'Failed', 'surecart' ), 'canceled' => __( 'Canceled', 'surecart' ), ]; foreach ( $stati as $status => $label ) { $link = \SureCart::getUrl()->index( 'orders' ); $current_link_attributes = ''; if ( ! empty( $_GET['status'] ) ) { if ( $status === $_GET['status'] ) { $current_link_attributes = ' class="current" aria-current="page"'; } } elseif ( 'all' === $status ) { $current_link_attributes = ' class="current" aria-current="page"'; } $link = add_query_arg( 'status', $status, $link ); $link = esc_url( $link ); $status_links[ $status ] = "" . $label . ''; } // filter links. return apply_filters( 'sc_order_status_links', $status_links ); } /** * Override the parent columns method. Defines the columns to use in your listing table * * @return array */ public function get_columns() { return array_merge( [ // 'cb' => '', 'order' => __( 'Order', 'surecart' ), 'status' => __( 'Status', 'surecart' ), 'fulfillment_status' => __( 'Fulfillment', 'surecart' ), 'shipment_status' => __( 'Shipping', 'surecart' ), 'method' => __( 'Method', 'surecart' ), 'integrations' => __( 'Integrations', 'surecart' ), 'total' => __( 'Total', 'surecart' ), 'type' => __( 'Type', 'surecart' ), 'created' => __( 'Date', 'surecart' ), 'mode' => '', ], parent::get_columns() ); } /** * Displays the checkbox column. * * @param Product $product The product model. */ public function column_cb( $product ) { ?> array( 'title', false ) ); } /** * Get the table data * * @return Array */ protected function table_data() { $mode = sanitize_text_field( wp_unslash( $_GET['mode'] ?? '' ) ); $conditions = [ 'status' => $this->getStatus(), 'fulfillment_status' => ! empty( $_GET['fulfillment_status'] ) ? [ $_GET['fulfillment_status'] ] : [], 'shipment_status' => ! empty( $_GET['shipment_status'] ) ? [ $_GET['shipment_status'] ] : [], 'query' => $this->get_search_query(), ]; if ( ! empty( $mode ) ) { $conditions['live_mode'] = 'live' === $mode; } return Order::where( $conditions ) ->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' ] ) ->paginate( [ 'per_page' => $this->get_items_per_page( 'orders' ), 'page' => $this->get_pagenum(), ] ); } /** * Get the archive query status. * * @return boolean|null */ public function getStatus() { $status = sanitize_text_field( wp_unslash( $_GET['status'] ?? 'all' ) ); if ( 'paid' === $status ) { return [ 'paid' ]; } if ( 'payment_failed' === $status ) { return [ 'payment_failed' ]; } if ( 'processing' === $status ) { return [ 'processing' ]; } if ( 'canceled' === $status ) { return [ 'void' ]; } if ( 'draft' === $status ) { return [ 'draft' ]; } if ( 'all' === $status ) { return []; } return $status ? [ esc_html( $status ) ] : []; } /** * Handle the total column * * @param \SureCart\Models\Order $order The order model. * * @return string */ public function column_total( $order ) { return $order->checkout->total_display_amount; } /** * Show the payment method for the order. * * @param \SureCart\Models\Order $order The order model. * * @return string */ public function column_method( $order ) { if ( isset( $order->checkout->manual_payment_method->name ) ) { return '' . esc_html( $order->checkout->manual_payment_method->name ) . ''; } ob_start(); ?> order_type ) && 'subscription' === $order->order_type ) { return '' . esc_html__( 'Subscription', 'surecart' ) . ''; } return '' . esc_html__( 'Checkout', 'surecart' ) . ''; } /** * Handle the status * * @param \SureCart\Models\Order $order Order Model. * * @return string */ public function column_status( $order ) { if ( ! empty( $order->checkout->charge->fully_refunded ) ) { return '' . __( 'Refunded', 'surecart' ) . ''; } if ( ! empty( $order->checkout->payment_method->processor_type ) && 'paypal' === $order->checkout->payment_method->processor_type ) { if ( 'requires_approval' === $order->status ) { return ''; } } return ''; } /** * Handle the status * * @param \SureCart\Models\Order $order Order Model. * * @return string */ public function column_fulfillment_status( $order ) { ob_start(); ?> checkout->selected_shipping_choice->shipping_method->name ) ? $order->checkout->selected_shipping_choice->shipping_method->name : false; ob_start(); ?> shipment_status ) : ?> -
()
#number ?? $order->id ); ?>
checkout->name ?? $order->checkout->email ?? $order->checkout->customer->name ?? $order->checkout->customer->email ) ); ?>
fulfillment_dropdown(); $this->shipment_dropdown(); $this->mode_dropdown(); /** * Fires before the Filter button on the Posts and Pages list tables. * * The Filter button allows sorting by date and/or category on the * Posts list table, and sorting by date on the Pages list table. * * @since 2.1.0 * @since 4.4.0 The `$post_type` parameter was added. * @since 4.6.0 The `$which` parameter was added. * * @param string $post_type The post type slug. * @param string $which The location of the extra table nav markup: * 'top' or 'bottom' for WP_Posts_List_Table, * 'bar' for WP_Media_List_Table. */ do_action( 'restrict_manage_orders', $this->screen->post_type, $which ); $output = ob_get_clean(); if ( ! empty( $output ) ) { echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped submit_button( __( 'Filter', 'surecart' ), '', 'filter_action', false, array( 'id' => 'filter-by-fulfillment-submit' ) ); } } ?>