# sellkit/1.2.1/includes/admin/components/analytics/discount/converted.php

SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster, version 1.2.1. 59 lines.

- Page: https://pluginprobe.com/plugins/sellkit/1.2.1/code/includes/admin/components/analytics/discount/converted.php
- Raw: https://pluginprobe.com/plugins/sellkit/1.2.1/raw/includes/admin/components/analytics/discount/converted.php
- Modified: 2022-05-04T06:26:46+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/sellkit/1.2.1/code/includes/admin/components/analytics/discount/converted.php#L10-L20`.

```php
<?php

namespace Sellkit\Admin\Components\Analytics\Discount;

use Sellkit\Admin\Components\Analytics;
use Sellkit\Admin\Components\Analytics\Analytics_Base;
use Sellkit\Database;

defined( 'ABSPATH' ) || die();

/**
 * Components class.
 *
 * @since 1.1.0
 */
class Converted extends Analytics_Base {

	/**
	 * Class constructor.
	 *
	 * @since 1.1.0
	 * @param int $rule_id Rule id.
	 */
	public function __construct( $rule_id ) {
		$this->target_id = $rule_id;

		$this->set_discounts_details();
	}

	/**
	 * Set discount details.
	 *
	 * @since 1.1.0
	 */
	public function set_discounts_details() {
		global $wpdb;

		$start_date = time() - ( 60 * 60 * 24 * Analytics::$date_range );

		$sellkit_prefix = Database::DATABASE_PREFIX;
		$discount_table = "{$wpdb->prefix}{$sellkit_prefix}applied_discount";

		// phpcs:disable
		$discounts = $wpdb->get_results(
			$wpdb->prepare( "SELECT FROM_UNIXTIME(applied_at, '%%b_%%d') as `day`, count(*) as total FROM {$discount_table}
				where applied_at > {$start_date} and `order_id` is not NULL and discount_id " . Analytics::target_id_condition( $this->target_id ) . " %d
				GROUP BY `day` ORDER BY `day` ASC", $this->target_id ),
			ARRAY_A );
		// phpcs:enable

		$prepared_discount = [];
		foreach ( $discounts as $discount ) {
			$prepared_discount[ $discount['day'] ] = intval( $discount['total'] );
		}

		$this->output = $prepared_discount;
	}
}

```
