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 '