WordPress at Your Fingertips
function is not described

Automattic\WooCommerce\Admin\API\Reports

DataStore::add_time_period_sql_params() protected WC 1.0

Fills WHERE clause of SQL request with date-related constraints.

{} It's a method of the class: DataStore{}

No Hooks.

Return

null. Nothing.

Usage

// protected - for code of main (parent) or child class
$result = $this->add_time_period_sql_params( $query_args, $table_name );
$query_args(array) (required)
Parameters supplied by the user.
$table_name(string) (required)
Name of the db table relevant for the date constraint.

Code of DataStore::add_time_period_sql_params() WC 6.1.0

protected function add_time_period_sql_params( $query_args, $table_name ) {
	$this->clear_sql_clause( array( 'from', 'where_time', 'where' ) );
	if ( isset( $this->subquery ) ) {
		$this->subquery->clear_sql_clause( 'where_time' );
	}

	if ( isset( $query_args['before'] ) && '' !== $query_args['before'] ) {
		if ( is_a( $query_args['before'], 'WC_DateTime' ) ) {
			$datetime_str = $query_args['before']->date( TimeInterval::$sql_datetime_format );
		} else {
			$datetime_str = $query_args['before']->format( TimeInterval::$sql_datetime_format );
		}
		if ( isset( $this->subquery ) ) {
			$this->subquery->add_sql_clause( 'where_time', "AND {$table_name}.date_created <= '$datetime_str'" );
		} else {
			$this->add_sql_clause( 'where_time', "AND {$table_name}.date_created <= '$datetime_str'" );
		}
	}

	if ( isset( $query_args['after'] ) && '' !== $query_args['after'] ) {
		if ( is_a( $query_args['after'], 'WC_DateTime' ) ) {
			$datetime_str = $query_args['after']->date( TimeInterval::$sql_datetime_format );
		} else {
			$datetime_str = $query_args['after']->format( TimeInterval::$sql_datetime_format );
		}
		if ( isset( $this->subquery ) ) {
			$this->subquery->add_sql_clause( 'where_time', "AND {$table_name}.date_created >= '$datetime_str'" );
		} else {
			$this->add_sql_clause( 'where_time', "AND {$table_name}.date_created >= '$datetime_str'" );
		}
	}
}