Automattic\WooCommerce\Internal\Admin\Orders

ListTable::set_order_args()privateWC 1.0

Updates the WC Order Query arguments as needed to support orderable columns.

Method of the class: ListTable{}

No Hooks.

Return

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->set_order_args();

ListTable::set_order_args() code WC 8.7.0

private function set_order_args() {
	$sortable  = $this->get_sortable_columns();
	$field     = sanitize_text_field( wp_unslash( $_GET['orderby'] ?? '' ) );
	$direction = strtoupper( sanitize_text_field( wp_unslash( $_GET['order'] ?? '' ) ) );

	if ( ! in_array( $field, $sortable, true ) ) {
		$this->order_query_args['orderby'] = 'date';
		$this->order_query_args['order']   = 'DESC';
		return;
	}

	$this->order_query_args['orderby'] = $field;
	$this->order_query_args['order']   = in_array( $direction, array( 'ASC', 'DESC' ), true ) ? $direction : 'ASC';
}