Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/woocomme.../src/Internal/Admin/Orders
File: ListTable.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Automattic\WooCommerce\Internal\Admin\Orders;
[2] Fix | Delete
[3] Fix | Delete
use Automattic\WooCommerce\Enums\OrderStatus;
[4] Fix | Delete
use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController;
[5] Fix | Delete
use Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableDataStore;
[6] Fix | Delete
use Automattic\WooCommerce\Caches\OrderCountCache;
[7] Fix | Delete
use Automattic\WooCommerce\Utilities\OrderUtil;
[8] Fix | Delete
use WC_Order;
[9] Fix | Delete
use WP_List_Table;
[10] Fix | Delete
use WP_Screen;
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* Admin list table for orders as managed by the OrdersTableDataStore.
[14] Fix | Delete
*/
[15] Fix | Delete
class ListTable extends WP_List_Table {
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* Order type.
[19] Fix | Delete
*
[20] Fix | Delete
* @var string
[21] Fix | Delete
*/
[22] Fix | Delete
private $order_type;
[23] Fix | Delete
[24] Fix | Delete
/**
[25] Fix | Delete
* Request vars.
[26] Fix | Delete
*
[27] Fix | Delete
* @var array
[28] Fix | Delete
*/
[29] Fix | Delete
private $request = array();
[30] Fix | Delete
[31] Fix | Delete
/**
[32] Fix | Delete
* Contains the arguments to be used in the order query.
[33] Fix | Delete
*
[34] Fix | Delete
* @var array
[35] Fix | Delete
*/
[36] Fix | Delete
private $order_query_args = array();
[37] Fix | Delete
[38] Fix | Delete
/**
[39] Fix | Delete
* Tracks if a filter (ie, date or customer filter) has been applied.
[40] Fix | Delete
*
[41] Fix | Delete
* @var bool
[42] Fix | Delete
*/
[43] Fix | Delete
private $has_filter = false;
[44] Fix | Delete
[45] Fix | Delete
/**
[46] Fix | Delete
* Page controller instance for this request.
[47] Fix | Delete
*
[48] Fix | Delete
* @var PageController
[49] Fix | Delete
*/
[50] Fix | Delete
private $page_controller;
[51] Fix | Delete
[52] Fix | Delete
/**
[53] Fix | Delete
* Tracks whether we're currently inside the trash.
[54] Fix | Delete
*
[55] Fix | Delete
* @var boolean
[56] Fix | Delete
*/
[57] Fix | Delete
private $is_trash = false;
[58] Fix | Delete
[59] Fix | Delete
/**
[60] Fix | Delete
* Caches order counts by status.
[61] Fix | Delete
*
[62] Fix | Delete
* @var array
[63] Fix | Delete
*/
[64] Fix | Delete
private $status_count_cache = null;
[65] Fix | Delete
[66] Fix | Delete
/**
[67] Fix | Delete
* Sets up the admin list table for orders (specifically, for orders managed by the OrdersTableDataStore).
[68] Fix | Delete
*
[69] Fix | Delete
* @see WC_Admin_List_Table_Orders for the corresponding class used in relation to the traditional WP Post store.
[70] Fix | Delete
*/
[71] Fix | Delete
public function __construct() {
[72] Fix | Delete
parent::__construct(
[73] Fix | Delete
array(
[74] Fix | Delete
'singular' => 'order',
[75] Fix | Delete
'plural' => 'orders',
[76] Fix | Delete
'ajax' => false,
[77] Fix | Delete
)
[78] Fix | Delete
);
[79] Fix | Delete
}
[80] Fix | Delete
[81] Fix | Delete
/**
[82] Fix | Delete
* Init method, invoked by DI container.
[83] Fix | Delete
*
[84] Fix | Delete
* @internal This method is not intended to be used directly (except for testing).
[85] Fix | Delete
* @param PageController $page_controller Page controller instance for this request.
[86] Fix | Delete
*/
[87] Fix | Delete
final public function init( PageController $page_controller ) {
[88] Fix | Delete
$this->page_controller = $page_controller;
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
/**
[92] Fix | Delete
* Performs setup work required before rendering the table.
[93] Fix | Delete
*
[94] Fix | Delete
* @param array $args Args to initialize this list table.
[95] Fix | Delete
*
[96] Fix | Delete
* @return void
[97] Fix | Delete
*/
[98] Fix | Delete
public function setup( $args = array() ): void {
[99] Fix | Delete
$this->order_type = $args['order_type'] ?? 'shop_order';
[100] Fix | Delete
[101] Fix | Delete
add_action( 'admin_notices', array( $this, 'bulk_action_notices' ) );
[102] Fix | Delete
add_filter( "manage_{$this->screen->id}_columns", array( $this, 'get_columns' ), 0 );
[103] Fix | Delete
add_filter( 'set_screen_option_edit_' . $this->order_type . '_per_page', array( $this, 'set_items_per_page' ), 10, 3 );
[104] Fix | Delete
add_filter( 'default_hidden_columns', array( $this, 'default_hidden_columns' ), 10, 2 );
[105] Fix | Delete
add_action( 'admin_footer', array( $this, 'enqueue_scripts' ) );
[106] Fix | Delete
add_action( 'woocommerce_order_list_table_restrict_manage_orders', array( $this, 'created_via_filter' ) );
[107] Fix | Delete
add_action( 'woocommerce_order_list_table_restrict_manage_orders', array( $this, 'customers_filter' ) );
[108] Fix | Delete
[109] Fix | Delete
$this->items_per_page();
[110] Fix | Delete
set_screen_options();
[111] Fix | Delete
[112] Fix | Delete
add_action( 'manage_' . wc_get_page_screen_id( $this->order_type ) . '_custom_column', array( $this, 'render_column' ), 10, 2 );
[113] Fix | Delete
}
[114] Fix | Delete
[115] Fix | Delete
/**
[116] Fix | Delete
* Generates content for a single row of the table.
[117] Fix | Delete
*
[118] Fix | Delete
* @since 7.8.0
[119] Fix | Delete
*
[120] Fix | Delete
* @param \WC_Order $order The current order.
[121] Fix | Delete
*/
[122] Fix | Delete
public function single_row( $order ) {
[123] Fix | Delete
/**
[124] Fix | Delete
* Filters the list of CSS class names for a given order row in the orders list table.
[125] Fix | Delete
*
[126] Fix | Delete
* @since 7.8.0
[127] Fix | Delete
*
[128] Fix | Delete
* @param string[] $classes An array of CSS class names.
[129] Fix | Delete
* @param \WC_Order $order The order object.
[130] Fix | Delete
*/
[131] Fix | Delete
$css_classes = apply_filters(
[132] Fix | Delete
'woocommerce_' . $this->order_type . '_list_table_order_css_classes',
[133] Fix | Delete
array(
[134] Fix | Delete
'order-' . $order->get_id(),
[135] Fix | Delete
'type-' . $order->get_type(),
[136] Fix | Delete
'status-' . $order->get_status(),
[137] Fix | Delete
),
[138] Fix | Delete
$order
[139] Fix | Delete
);
[140] Fix | Delete
$css_classes = array_unique( array_map( 'trim', $css_classes ) );
[141] Fix | Delete
[142] Fix | Delete
// Is locked?
[143] Fix | Delete
$edit_lock = wc_get_container()->get( EditLock::class );
[144] Fix | Delete
if ( $edit_lock->is_locked_by_another_user( $order ) ) {
[145] Fix | Delete
$css_classes[] = 'wp-locked';
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
echo '<tr id="order-' . esc_attr( $order->get_id() ) . '" class="' . esc_attr( implode( ' ', $css_classes ) ) . '">';
[149] Fix | Delete
$this->single_row_columns( $order );
[150] Fix | Delete
echo '</tr>';
[151] Fix | Delete
}
[152] Fix | Delete
[153] Fix | Delete
/**
[154] Fix | Delete
* Render individual column.
[155] Fix | Delete
*
[156] Fix | Delete
* @param string $column_id Column ID to render.
[157] Fix | Delete
* @param WC_Order $order Order object.
[158] Fix | Delete
*/
[159] Fix | Delete
public function render_column( $column_id, $order ) {
[160] Fix | Delete
if ( ! $order ) {
[161] Fix | Delete
return;
[162] Fix | Delete
}
[163] Fix | Delete
[164] Fix | Delete
if ( is_callable( array( $this, 'render_' . $column_id . '_column' ) ) ) {
[165] Fix | Delete
call_user_func( array( $this, 'render_' . $column_id . '_column' ), $order );
[166] Fix | Delete
}
[167] Fix | Delete
}
[168] Fix | Delete
[169] Fix | Delete
/**
[170] Fix | Delete
* Handles output for the default column.
[171] Fix | Delete
*
[172] Fix | Delete
* @param \WC_Order $order Current WooCommerce order object.
[173] Fix | Delete
* @param string $column_name Identifier for the custom column.
[174] Fix | Delete
*/
[175] Fix | Delete
public function column_default( $order, $column_name ) {
[176] Fix | Delete
/**
[177] Fix | Delete
* Fires for each custom column for a specific order type. This hook takes precedence over the generic
[178] Fix | Delete
* action `manage_{$this->screen->id}_custom_column`.
[179] Fix | Delete
*
[180] Fix | Delete
* @param string $column_name Identifier for the custom column.
[181] Fix | Delete
* @param \WC_Order $order Current WooCommerce order object.
[182] Fix | Delete
*
[183] Fix | Delete
* @since 7.3.0
[184] Fix | Delete
*/
[185] Fix | Delete
do_action( 'woocommerce_' . $this->order_type . '_list_table_custom_column', $column_name, $order );
[186] Fix | Delete
[187] Fix | Delete
/**
[188] Fix | Delete
* Fires for each custom column in the Custom Order Table in the administrative screen.
[189] Fix | Delete
*
[190] Fix | Delete
* @param string $column_name Identifier for the custom column.
[191] Fix | Delete
* @param \WC_Order $order Current WooCommerce order object.
[192] Fix | Delete
*
[193] Fix | Delete
* @since 7.0.0
[194] Fix | Delete
*/
[195] Fix | Delete
do_action( "manage_{$this->screen->id}_custom_column", $column_name, $order );
[196] Fix | Delete
}
[197] Fix | Delete
[198] Fix | Delete
/**
[199] Fix | Delete
* Sets up an items-per-page control.
[200] Fix | Delete
*/
[201] Fix | Delete
private function items_per_page(): void {
[202] Fix | Delete
add_screen_option(
[203] Fix | Delete
'per_page',
[204] Fix | Delete
array(
[205] Fix | Delete
'default' => 20,
[206] Fix | Delete
'option' => 'edit_' . $this->order_type . '_per_page',
[207] Fix | Delete
)
[208] Fix | Delete
);
[209] Fix | Delete
}
[210] Fix | Delete
[211] Fix | Delete
/**
[212] Fix | Delete
* Saves the items-per-page setting.
[213] Fix | Delete
*
[214] Fix | Delete
* @param mixed $default The default value.
[215] Fix | Delete
* @param string $option The option being configured.
[216] Fix | Delete
* @param int $value The submitted option value.
[217] Fix | Delete
*
[218] Fix | Delete
* @return mixed
[219] Fix | Delete
*/
[220] Fix | Delete
public function set_items_per_page( $default, string $option, int $value ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.defaultFound -- backwards compat.
[221] Fix | Delete
return 'edit_' . $this->order_type . '_per_page' === $option ? absint( $value ) : $default;
[222] Fix | Delete
}
[223] Fix | Delete
[224] Fix | Delete
/**
[225] Fix | Delete
* Render the table.
[226] Fix | Delete
*
[227] Fix | Delete
* @return void
[228] Fix | Delete
*/
[229] Fix | Delete
public function display() {
[230] Fix | Delete
$post_type = get_post_type_object( $this->order_type );
[231] Fix | Delete
[232] Fix | Delete
$title = esc_html( $post_type->labels->name );
[233] Fix | Delete
$add_new = esc_html( $post_type->labels->add_new );
[234] Fix | Delete
$new_page_link = $this->page_controller->get_new_page_url( $this->order_type );
[235] Fix | Delete
$search_label = '';
[236] Fix | Delete
[237] Fix | Delete
if ( ! empty( $this->order_query_args['s'] ) ) {
[238] Fix | Delete
$search_label = '<span class="subtitle">';
[239] Fix | Delete
$search_label .= sprintf(
[240] Fix | Delete
/* translators: %s: Search query. */
[241] Fix | Delete
__( 'Search results for: %s', 'woocommerce' ),
[242] Fix | Delete
'<strong>' . esc_html( $this->order_query_args['s'] ) . '</strong>'
[243] Fix | Delete
);
[244] Fix | Delete
$search_label .= '</span>';
[245] Fix | Delete
}
[246] Fix | Delete
[247] Fix | Delete
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[248] Fix | Delete
echo wp_kses_post(
[249] Fix | Delete
"
[250] Fix | Delete
<div class='wrap'>
[251] Fix | Delete
<h1 class='wp-heading-inline'>{$title}</h1>
[252] Fix | Delete
<a href='" . esc_url( $new_page_link ) . "' class='page-title-action'>{$add_new}</a>
[253] Fix | Delete
{$search_label}
[254] Fix | Delete
<hr class='wp-header-end'>"
[255] Fix | Delete
);
[256] Fix | Delete
[257] Fix | Delete
if ( $this->should_render_blank_state() ) {
[258] Fix | Delete
$this->render_blank_state();
[259] Fix | Delete
return;
[260] Fix | Delete
}
[261] Fix | Delete
[262] Fix | Delete
$this->views();
[263] Fix | Delete
[264] Fix | Delete
echo '<form id="wc-orders-filter" method="get" action="' . esc_url( get_admin_url( null, 'admin.php' ) ) . '">';
[265] Fix | Delete
$this->print_hidden_form_fields();
[266] Fix | Delete
$this->search_box( esc_html__( 'Search orders', 'woocommerce' ), 'orders-search-input' );
[267] Fix | Delete
[268] Fix | Delete
parent::display();
[269] Fix | Delete
echo '</form> </div>';
[270] Fix | Delete
}
[271] Fix | Delete
[272] Fix | Delete
/**
[273] Fix | Delete
* Renders advice in the event that no orders exist yet.
[274] Fix | Delete
*
[275] Fix | Delete
* @return void
[276] Fix | Delete
*/
[277] Fix | Delete
public function render_blank_state(): void {
[278] Fix | Delete
?>
[279] Fix | Delete
<div class="woocommerce-BlankState">
[280] Fix | Delete
[281] Fix | Delete
<h2 class="woocommerce-BlankState-message">
[282] Fix | Delete
<?php esc_html_e( 'When you receive a new order, it will appear here.', 'woocommerce' ); ?>
[283] Fix | Delete
</h2>
[284] Fix | Delete
[285] Fix | Delete
<div class="woocommerce-BlankState-buttons">
[286] Fix | Delete
<a class="woocommerce-BlankState-cta button-primary button" target="_blank" href="https://woocommerce.com/document/managing-orders/?utm_source=blankslate&utm_medium=product&utm_content=ordersdoc&utm_campaign=woocommerceplugin"><?php esc_html_e( 'Learn more about orders', 'woocommerce' ); ?></a>
[287] Fix | Delete
</div>
[288] Fix | Delete
[289] Fix | Delete
<?php
[290] Fix | Delete
/**
[291] Fix | Delete
* Renders after the 'blank state' message for the order list table has rendered.
[292] Fix | Delete
*
[293] Fix | Delete
* @since 6.6.1
[294] Fix | Delete
*/
[295] Fix | Delete
do_action( 'wc_marketplace_suggestions_orders_empty_state' ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingSinceComment
[296] Fix | Delete
?>
[297] Fix | Delete
[298] Fix | Delete
</div>
[299] Fix | Delete
<?php
[300] Fix | Delete
}
[301] Fix | Delete
[302] Fix | Delete
/**
[303] Fix | Delete
* Retrieves the list of bulk actions available for this table.
[304] Fix | Delete
*
[305] Fix | Delete
* @return array
[306] Fix | Delete
*/
[307] Fix | Delete
protected function get_bulk_actions() {
[308] Fix | Delete
$selected_status = $this->order_query_args['status'] ?? false;
[309] Fix | Delete
[310] Fix | Delete
if ( array( 'trash' ) === $selected_status ) {
[311] Fix | Delete
$actions = array(
[312] Fix | Delete
'untrash' => __( 'Restore', 'woocommerce' ),
[313] Fix | Delete
'delete' => __( 'Delete permanently', 'woocommerce' ),
[314] Fix | Delete
);
[315] Fix | Delete
} else {
[316] Fix | Delete
$actions = array(
[317] Fix | Delete
'mark_processing' => __( 'Change status to processing', 'woocommerce' ),
[318] Fix | Delete
'mark_on-hold' => __( 'Change status to on-hold', 'woocommerce' ),
[319] Fix | Delete
'mark_completed' => __( 'Change status to completed', 'woocommerce' ),
[320] Fix | Delete
'mark_cancelled' => __( 'Change status to cancelled', 'woocommerce' ),
[321] Fix | Delete
'trash' => __( 'Move to Trash', 'woocommerce' ),
[322] Fix | Delete
);
[323] Fix | Delete
}
[324] Fix | Delete
[325] Fix | Delete
if ( wc_string_to_bool( get_option( 'woocommerce_allow_bulk_remove_personal_data', 'no' ) ) ) {
[326] Fix | Delete
$actions['remove_personal_data'] = __( 'Remove personal data', 'woocommerce' );
[327] Fix | Delete
}
[328] Fix | Delete
[329] Fix | Delete
return $actions;
[330] Fix | Delete
}
[331] Fix | Delete
[332] Fix | Delete
/**
[333] Fix | Delete
* Gets a list of CSS classes for the WP_List_Table table tag.
[334] Fix | Delete
*
[335] Fix | Delete
* @since 7.8.0
[336] Fix | Delete
*
[337] Fix | Delete
* @return string[] Array of CSS classes for the table tag.
[338] Fix | Delete
*/
[339] Fix | Delete
protected function get_table_classes() {
[340] Fix | Delete
/**
[341] Fix | Delete
* Filters the list of CSS class names for the orders list table.
[342] Fix | Delete
*
[343] Fix | Delete
* @since 7.8.0
[344] Fix | Delete
*
[345] Fix | Delete
* @param string[] $classes An array of CSS class names.
[346] Fix | Delete
* @param string $order_type The order type.
[347] Fix | Delete
*/
[348] Fix | Delete
$css_classes = apply_filters(
[349] Fix | Delete
'woocommerce_' . $this->order_type . '_list_table_css_classes',
[350] Fix | Delete
array_merge(
[351] Fix | Delete
parent::get_table_classes(),
[352] Fix | Delete
array(
[353] Fix | Delete
'wc-orders-list-table',
[354] Fix | Delete
'wc-orders-list-table-' . $this->order_type,
[355] Fix | Delete
)
[356] Fix | Delete
),
[357] Fix | Delete
$this->order_type
[358] Fix | Delete
);
[359] Fix | Delete
[360] Fix | Delete
return array_unique( array_map( 'trim', $css_classes ) );
[361] Fix | Delete
}
[362] Fix | Delete
[363] Fix | Delete
/**
[364] Fix | Delete
* Prepares the list of items for displaying.
[365] Fix | Delete
*/
[366] Fix | Delete
public function prepare_items() {
[367] Fix | Delete
$limit = $this->get_items_per_page( 'edit_' . $this->order_type . '_per_page' );
[368] Fix | Delete
[369] Fix | Delete
$this->order_query_args = array(
[370] Fix | Delete
'limit' => $limit,
[371] Fix | Delete
'page' => $this->get_pagenum(),
[372] Fix | Delete
'paginate' => true,
[373] Fix | Delete
'type' => $this->order_type,
[374] Fix | Delete
);
[375] Fix | Delete
[376] Fix | Delete
foreach ( array( 'status', 's', 'm', '_customer_user', 'search-filter' ) as $query_var ) {
[377] Fix | Delete
$this->request[ $query_var ] = sanitize_text_field( wp_unslash( $_REQUEST[ $query_var ] ?? '' ) );
[378] Fix | Delete
}
[379] Fix | Delete
[380] Fix | Delete
/**
[381] Fix | Delete
* Allows 3rd parties to filter the initial request vars before defaults and other logic is applied.
[382] Fix | Delete
*
[383] Fix | Delete
* @param array $request Request to be passed to `wc_get_orders()`.
[384] Fix | Delete
*
[385] Fix | Delete
* @since 7.3.0
[386] Fix | Delete
*/
[387] Fix | Delete
$this->request = apply_filters( 'woocommerce_' . $this->order_type . '_list_table_request', $this->request );
[388] Fix | Delete
[389] Fix | Delete
$this->set_status_args();
[390] Fix | Delete
$this->set_order_args();
[391] Fix | Delete
$this->set_date_args();
[392] Fix | Delete
$this->set_customer_args();
[393] Fix | Delete
$this->set_search_args();
[394] Fix | Delete
$this->set_created_via_args();
[395] Fix | Delete
[396] Fix | Delete
/**
[397] Fix | Delete
* Provides an opportunity to modify the query arguments used in the (Custom Order Table-powered) order list
[398] Fix | Delete
* table.
[399] Fix | Delete
*
[400] Fix | Delete
* @since 6.9.0
[401] Fix | Delete
*
[402] Fix | Delete
* @param array $query_args Arguments to be passed to `wc_get_orders()`.
[403] Fix | Delete
*/
[404] Fix | Delete
$order_query_args = (array) apply_filters( 'woocommerce_order_list_table_prepare_items_query_args', $this->order_query_args );
[405] Fix | Delete
[406] Fix | Delete
/**
[407] Fix | Delete
* Same as `woocommerce_order_list_table_prepare_items_query_args` but for a specific order type.
[408] Fix | Delete
*
[409] Fix | Delete
* @param array $query_args Arguments to be passed to `wc_get_orders()`.
[410] Fix | Delete
*
[411] Fix | Delete
* @since 7.3.0
[412] Fix | Delete
*/
[413] Fix | Delete
$order_query_args = apply_filters( 'woocommerce_' . $this->order_type . '_list_table_prepare_items_query_args', $order_query_args );
[414] Fix | Delete
[415] Fix | Delete
// We must ensure the 'paginate' argument is set.
[416] Fix | Delete
$order_query_args['paginate'] = true;
[417] Fix | Delete
[418] Fix | Delete
// Attempt to use cache if no additional query arguments are used.
[419] Fix | Delete
if ( empty( array_diff( array_keys( $this->order_query_args ), array( 'limit', 'page', 'paginate', 'type', 'status', 'orderby', 'order' ) ) ) ) {
[420] Fix | Delete
$this->order_query_args['no_found_rows'] = true;
[421] Fix | Delete
$order_query_args['no_found_rows'] = true;
[422] Fix | Delete
}
[423] Fix | Delete
[424] Fix | Delete
$orders = wc_get_orders( $order_query_args );
[425] Fix | Delete
$this->items = $orders->orders;
[426] Fix | Delete
[427] Fix | Delete
$max_num_pages = $this->get_max_num_pages( $orders );
[428] Fix | Delete
[429] Fix | Delete
// Check in case the user has attempted to page beyond the available range of orders.
[430] Fix | Delete
if ( 0 === $max_num_pages && $this->order_query_args['page'] > 1 ) {
[431] Fix | Delete
$count_query_args = $order_query_args;
[432] Fix | Delete
$count_query_args['page'] = 1;
[433] Fix | Delete
$count_query_args['limit'] = 1;
[434] Fix | Delete
$order_count = wc_get_orders( $count_query_args );
[435] Fix | Delete
$max_num_pages = (int) ceil( $order_count->total / $order_query_args['limit'] );
[436] Fix | Delete
}
[437] Fix | Delete
[438] Fix | Delete
$this->set_pagination_args(
[439] Fix | Delete
array(
[440] Fix | Delete
'total_items' => $orders->total ?? 0,
[441] Fix | Delete
'per_page' => $limit,
[442] Fix | Delete
'total_pages' => $max_num_pages,
[443] Fix | Delete
)
[444] Fix | Delete
);
[445] Fix | Delete
[446] Fix | Delete
// Are we inside the trash?
[447] Fix | Delete
$this->is_trash = 'trash' === $this->request['status'];
[448] Fix | Delete
}
[449] Fix | Delete
[450] Fix | Delete
/**
[451] Fix | Delete
* Get the max number of pages from orders or from cache.
[452] Fix | Delete
*
[453] Fix | Delete
* @param WC_Order[]|stdClass Number of pages and an array of order objects.
[454] Fix | Delete
* @return int
[455] Fix | Delete
*/
[456] Fix | Delete
private function get_max_num_pages( &$orders ) {
[457] Fix | Delete
if ( ! isset( $this->order_query_args['no_found_rows'] ) || ! $this->order_query_args['no_found_rows'] ) {
[458] Fix | Delete
return $orders->max_num_pages;
[459] Fix | Delete
}
[460] Fix | Delete
[461] Fix | Delete
$count = $this->count_orders_by_status( $this->order_query_args['status'] );
[462] Fix | Delete
$limit = $this->get_items_per_page( 'edit_' . $this->order_type . '_per_page' );
[463] Fix | Delete
$orders->total = $count;
[464] Fix | Delete
[465] Fix | Delete
return ceil( $count / $limit );
[466] Fix | Delete
}
[467] Fix | Delete
[468] Fix | Delete
/**
[469] Fix | Delete
* Updates the WC Order Query arguments as needed to support orderable columns.
[470] Fix | Delete
*/
[471] Fix | Delete
private function set_order_args() {
[472] Fix | Delete
$sortable = $this->get_sortable_columns();
[473] Fix | Delete
$field = sanitize_text_field( wp_unslash( $_GET['orderby'] ?? '' ) );
[474] Fix | Delete
$direction = strtoupper( sanitize_text_field( wp_unslash( $_GET['order'] ?? '' ) ) );
[475] Fix | Delete
[476] Fix | Delete
if ( ! in_array( $field, $sortable, true ) ) {
[477] Fix | Delete
$this->order_query_args['orderby'] = 'date';
[478] Fix | Delete
$this->order_query_args['order'] = 'DESC';
[479] Fix | Delete
return;
[480] Fix | Delete
}
[481] Fix | Delete
[482] Fix | Delete
$this->order_query_args['orderby'] = $field;
[483] Fix | Delete
$this->order_query_args['order'] = in_array( $direction, array( 'ASC', 'DESC' ), true ) ? $direction : 'ASC';
[484] Fix | Delete
}
[485] Fix | Delete
[486] Fix | Delete
/**
[487] Fix | Delete
* Implements date (month-based) filtering.
[488] Fix | Delete
*/
[489] Fix | Delete
private function set_date_args() {
[490] Fix | Delete
$year_month = sanitize_text_field( wp_unslash( $_GET['m'] ?? '' ) );
[491] Fix | Delete
[492] Fix | Delete
if ( empty( $year_month ) || ! preg_match( '/^[0-9]{6}$/', $year_month ) ) {
[493] Fix | Delete
return;
[494] Fix | Delete
}
[495] Fix | Delete
[496] Fix | Delete
$year = (int) substr( $year_month, 0, 4 );
[497] Fix | Delete
$month = (int) substr( $year_month, 4, 2 );
[498] Fix | Delete
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function