'order',
'plural' => 'orders',
'ajax' => false
) );
// Use registered types
$types = array_keys( edd_get_order_types() );
if ( ! empty( $_GET['order_type'] ) && in_array( $_GET['order_type'], $types, true ) ) {
$this->type = sanitize_key( $_GET['order_type'] );
// Default to 'sale' if type is unrecognized
} else {
$this->type = 'sale';
}
$this->set_base_url();
$this->filter_bar_hooks();
$this->get_payment_counts();
}
/**
* Set the base URL.
*
* This retains the current order-type, or 'sale' by default.
*
* @since 3.0
*/
private function set_base_url() {
// Carry the type over to the base URL
$this->base_url = edd_get_admin_url( array(
'page' => 'edd-payment-history',
'order_type' => sanitize_key( $this->type ),
) );
}
/**
* Hook in filter bar actions
*
* @since 3.0
*/
private function filter_bar_hooks() {
add_action( 'edd_admin_filter_bar_orders', array( $this, 'filter_bar_items' ) );
add_action( 'edd_after_admin_filter_bar_orders', array( $this, 'filter_bar_searchbox' ) );
}
/**
* Display advanced filters.
*
* @since 1.4
* @since 3.0 Add a filter for modes.
* Display 'Advanced Filters'
*/
public function advanced_filters() {
// Hide when viewing Refunds.
if ( 'refund' === $this->type ) {
return;
}
edd_admin_filter_bar( 'orders' );
}
/**
* Output filter bar items
*
* @since 3.0
*/
public function filter_bar_items() {
// Get values
$start_date = isset( $_GET['start-date'] ) ? sanitize_text_field( $_GET['start-date'] ) : null;
$end_date = isset( $_GET['end-date'] ) ? sanitize_text_field( $_GET['end-date'] ) : null;
$gateway = isset( $_GET['gateway'] ) ? sanitize_key( $_GET['gateway'] ) : 'all';
$mode = isset( $_GET['mode'] ) ? sanitize_key( $_GET['mode'] ) : 'all';
$order_total_filter_type = isset( $_GET['order-amount-filter-type'] ) ? sanitize_text_field( $_GET['order-amount-filter-type'] ) : false;
$order_total_filter_amount = isset( $_GET['order-amount-filter-value'] ) ? sanitize_text_field( $_GET['order-amount-filter-value'] ) : '';
$country = isset( $_GET['order-country-filter-value'] ) ? sanitize_text_field( $_GET['order-country-filter-value'] ) : '';
$region = isset( $_GET['order-region-filter-value'] ) ? sanitize_text_field( $_GET['order-region-filter-value'] ) : '';
$product_id = ! empty( $_GET['product-id'] ) ? sanitize_text_field( $_GET['product-id'] ) : false;
$status = $this->get_status();
$clear_url = $this->base_url;
// Filters
$all_modes = edd_get_payment_modes();
$all_gateways = edd_get_payment_gateways();
// No modes
if ( empty( $all_modes ) ) {
$modes = array();
// Add "All" and pluck labels
} else {
$modes = array_merge( array(
'all' => __( 'All modes', 'easy-digital-downloads' )
), wp_list_pluck( $all_modes, 'admin_label' ) );
}
// No gateways
if ( empty( $all_gateways ) ) {
$gateways = array();
// Add "All" and pluck labels
} else {
$gateways = array_merge( array(
'all' => __( 'All gateways', 'easy-digital-downloads' )
), wp_list_pluck( $all_gateways, 'admin_label' ) );
}
/**
* Allow gateways that aren't registered the standard way to be displayed in the dropdown.
*
* @since 2.8.11
*/
$gateways = apply_filters( 'edd_payments_table_gateways', $gateways );
// Output the items
if ( ! empty( $modes ) ) : ?>
html->select( array(
'options' => $modes,
'name' => 'mode',
'id' => 'mode',
'selected' => $mode,
'show_option_all' => false,
'show_option_none' => false
) ); ?>
html->date_field( array(
'id' => 'start-date',
'name' => 'start-date',
'placeholder' => _x( 'From', 'date filter', 'easy-digital-downloads' ),
'value' => $start_date
) );
echo EDD()->html->date_field( array(
'id' => 'end-date',
'name' => 'end-date',
'placeholder' => _x( 'To', 'date filter', 'easy-digital-downloads' ),
'value' => $end_date
) );
?>
html->select( array(
'options' => $gateways,
'name' => 'gateway',
'id' => 'gateway',
'selected' => $gateway,
'show_option_all' => false,
'show_option_none' => false
) ); ?>
get_var( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'edd_payment' LIMIT 1" ); if ( ! empty( $orders ) ) { esc_html_e( 'Easy Digital Downloads needs to upgrade the database. Orders will be available when that has completed.', 'easy-digital-downloads' ); return; } } esc_html_e( 'No orders found.', 'easy-digital-downloads' ); } /** * Retrieve the table columns. * * @since 1.4 * * @return array $columns Array of all the list table columns. */ public function get_columns() { $columns = array( 'cb' => '', // Render a checkbox instead of text 'number' => __( 'Number', 'easy-digital-downloads' ), 'customer' => __( 'Customer', 'easy-digital-downloads' ), 'gateway' => __( 'Gateway', 'easy-digital-downloads' ), 'amount' => __( 'Total', 'easy-digital-downloads' ), 'date' => __( 'Date', 'easy-digital-downloads' ), 'status' => __( 'Status', 'easy-digital-downloads' ), ); if ( 'refund' === $this->type ) { unset( $columns['status'] ); } /** * Filters the columns for Orders and Refunds table. * * @since unknown * * @param array $columns Table columns. */ $columns = apply_filters( 'edd_payments_table_columns', $columns ); return $columns; } /** * Retrieve the sortable columns. * * @since 1.4 * * @return array Array of all the sortable columns. */ public function get_sortable_columns() { return apply_filters( 'edd_payments_table_sortable_columns', array( 'number' => array( 'id', true ), 'status' => array( 'status', false ), 'customer' => array( 'customer_id', false ), 'gateway' => array( 'gateway', false ), 'amount' => array( 'total', false ), 'date' => array( 'date_created', false ) ) ); } /** * Gets the name of the primary column. * * @since 2.5 * @access protected * * @return string Name of the primary column. */ protected function get_primary_column_name() { return 'number'; } /** * This function renders most of the columns in the list table. * * @since 1.4 * @since 3.0 Updated to use the new EDD\Orders\Order class. * * @param EDD\Orders\Order $order Order object. * @param string $column_name The name of the column. * * @return string Column name. */ public function column_default( $order, $column_name ) { $timezone_abbreviation = edd_get_timezone_abbr(); switch ( $column_name ) { case 'amount': $currency = ! empty( $order->currency ) ? $order->currency : edd_get_currency(); $value = edd_display_amount( $order->total, $currency ); break; case 'date': $value = ''; break; case 'gateway': $value = edd_get_gateway_admin_label( $order->gateway ); if ( empty( $value ) ) { $value = '—'; } break; case 'status': $value = edd_get_order_status_badge( $order->status ); break; default: $value = method_exists( $order, 'get_' . $column_name ) ? call_user_func( array( $order, 'get_' . $column_name ) ) : ''; break; } return apply_filters( 'edd_payments_table_column', $value, $order->id, $column_name ); } /** * Render the checkbox column. * * @since 1.4 * @since 3.0 Updated to use the new EDD\Orders\Order class. * * @param EDD\Orders\Order $order Order object. * @return string Displays a checkbox. */ public function column_cb( $order ) { $order_number = 'sale' === $order->type ? $order->get_number() : $order->order_number; return sprintf( '', 'order', absint( $order->id ), /* translators: the order number */ esc_html( sprintf( __( 'Select %s', 'easy-digital-downloads' ), $order_number ) ) ); } /** * Render the ID column. * * @since 2.0 * @since 3.0 Updated to use the new EDD\Orders\Order class. * * @param EDD\Orders\Order $order Order object. * @return string Displays a checkbox. */ public function column_number( $order ) { $status = $this->get_status(); // View URL $view_url = edd_get_admin_url( array( 'page' => 'edd-payment-history', 'view' => 'sale' === $order->type ? 'view-order-details' : 'view-refund-details', 'id' => absint( $order->id ), ) ); // Default row actions $row_actions = array( 'view' => '' . esc_html__( 'Edit', 'easy-digital-downloads' ) . '', ); // View receipt if ( 'sale' === $order->type && edd_can_view_receipt( $order->payment_key ) ) { $row_actions['receipt'] = sprintf( '%s', edd_get_receipt_page_uri( $order->id ), __( 'View Receipt', 'easy-digital-downloads' ) ); } // Resend Receipt if ( 'sale' === $this->type && 'complete' === $order->status && ! empty( $order->email ) ) { $row_actions['email_links'] = '' . __( 'Resend Receipt', 'easy-digital-downloads' ) . ''; } // Keep Delete at the end if ( edd_is_order_trashable( $order->id ) ) { $trash_url = wp_nonce_url( add_query_arg( array( 'edd-action' => 'trash_order', 'purchase_id' => absint( $order->id ), ), $this->base_url ), 'edd_payment_nonce' ); $row_actions['trash'] = '' . esc_html__( 'Trash', 'easy-digital-downloads' ) . ''; } elseif ( edd_is_order_restorable( $order->id ) ) { $restore_url = wp_nonce_url( add_query_arg( array( 'edd-action' => 'restore_order', 'purchase_id' => absint( $order->id ), ), $this->base_url ), 'edd_payment_nonce' ); $row_actions['restore'] = '' . esc_html__( 'Restore', 'easy-digital-downloads' ) . ''; $delete_url = wp_nonce_url( add_query_arg( array( 'edd-action' => 'delete_order', 'purchase_id' => absint( $order->id ), ), $this->base_url ), 'edd_payment_nonce' ); $row_actions['delete'] = '' . esc_html__( 'Delete Permanently', 'easy-digital-downloads' ) . ''; unset( $row_actions['view'] ); } if ( has_filter( 'edd_payment_row_actions' ) ) { $payment = edd_get_payment( $order->id ); /** * Filters the row actions. * * @deprecated 3.0 * * @param array $row_actions * @param EDD_Payment|false $payment */ $row_actions = apply_filters_deprecated( 'edd_payment_row_actions', array( $row_actions, $payment ), '3.0', 'edd_order_row_actions' ); } /** * Filters the row actions. * * @param array $row_actions Array of row actions. * @param EDD\Orders\Order $order Order object. * * @since 3.0 */ $row_actions = apply_filters( 'edd_order_row_actions', $row_actions, $order ); // Row actions $actions = $this->row_actions( $row_actions ); // Primary link $order_number = 'sale' === $order->type ? $order->get_number() : $order->order_number; $link = edd_is_order_restorable( $order->id ) ? '' . esc_html( $order_number ) . '' : '' . esc_html( $order_number ) . ''; // Concatenate & return the results return $link . $actions; } /** * Render the Customer column. * * @since 2.4.3 * @since 3.0 Updated to use the new EDD\Orders\Order class. * * @param EDD\Orders\Order $order Order object. * @return string Data shown in the Customer column. */ public function column_customer( $order ) { $customer_id = $order->customer_id; $customer = edd_get_customer( $customer_id ); // Actions if exists if ( ! empty( $customer ) ) { // Use customer name, if exists $name = ! empty( $customer->name ) ? $customer->name : $order->email; // Link to View Customer $url = edd_get_admin_url( array( 'page' => 'edd-customers', 'view' => 'overview', 'id' => absint( $customer_id ), ) ); $name = '' . esc_html( $name ) . ''; if ( ! empty( $customer->name ) ) { $name .= '