Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors

TotalPaymentsVolumeProcessor::process │ public │ WC 1.0

Compare against the store's total payments volume.

Метод класса: TotalPaymentsVolumeProcessor{}

Хуков нет.

Возвращает

bool. The result of the operation.

Использование

$TotalPaymentsVolumeProcessor = new TotalPaymentsVolumeProcessor();
$TotalPaymentsVolumeProcessor->process( $rule, $stored_state );
$rule(объект) (обязательный)
The rule being processed by this rule processor.
$stored_state(объект) (обязательный)
Stored state.

Код TotalPaymentsVolumeProcessor::process() WC 11.2.2

public function process( $rule, $stored_state ) {
	// The timeframe must be resolved against the site's calendar date: the report query
	// parses the returned boundary strings as site-local datetimes. Work on a fresh
	// instance: the date calculations modify it in place, and the provider's own object
	// (which an implementation may cache and return again) must not absorb that.
	$now   = ( new \DateTime( '@' . $this->date_time_provider->get_now()->getTimestamp() ) )->setTimezone( wp_timezone() );
	$dates = TimeInterval::get_timeframe_dates( $rule->timeframe, $now );

	if ( false === $dates ) {
		return false;
	}

	$reports_revenue = $this->get_reports_query(
		array(
			'before'   => $dates['end'],
			'after'    => $dates['start'],
			'interval' => 'year',
			'fields'   => array( 'total_sales' ),
		)
	);
	$report_data     = $reports_revenue->get_data();

	if ( ! $report_data || ! isset( $report_data->totals->total_sales ) ) {
		return false;
	}

	$value = $report_data->totals->total_sales;

	return ComparisonOperation::compare(
		$value,
		$rule->value,
		$rule->operation
	);
}