PluginProbe
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster / trunk
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster vtrunk
2.6.0 trunk 1.1.0 1.1.4 1.2.1 1.2.2 1.2.3 1.2.5 1.2.9 1.3.1 1.3.2 1.5.0 1.5.1 1.5.4 1.5.7 1.5.8 1.5.9 1.6.2 1.6.5 1.6.8 1.7.2 1.7.4 1.7.5 1.7.9 1.8.1 All 42 releases
sellkit / includes / admin / components / analytics / funnel / conversion-rate.php

conversion-rate.php in SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster trunk, at includes/admin/components/analytics/funnel/conversion-rate.php

64 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Sellkit\Admin\Components\Analytics\Funnel;
4
5 use Sellkit\Admin\Components\Analytics;
6 use Sellkit\Admin\Components\Analytics\Analytics_Base;
7 use Sellkit\Database;
8
9 defined( 'ABSPATH' ) || die();
10
11 /**
12 * Conversion Rate class.
13 *
14 * @since 1.1.0
15 */
16 class Conversion_Rate extends Analytics_Base {
17
18 /**
19 * Class constructor.
20 *
21 * @since 1.1.0
22 * @param int $funnel_id Rule id.
23 */
24 public function __construct( $funnel_id ) {
25 $this->target_id = $funnel_id;
26
27 $this->set_alert_details();
28 }
29
30 /**
31 * Set discount details.
32 *
33 * @since 1.1.0
34 */
35 public function set_alert_details() {
36 global $wpdb;
37
38 $start_date = time() - ( 60 * 60 * 24 * Analytics::$date_range );
39
40 $sellkit_prefix = Database::DATABASE_PREFIX;
41 $funnel_table = "{$wpdb->prefix}{$sellkit_prefix}applied_funnel";
42
43 // phpcs:disable
44 $results = $wpdb->get_results(
45 $wpdb->prepare( "SELECT FROM_UNIXTIME(applied_at, '%%b_%%d') as `day`,
46 SUM(is_started_number) as total_started, SUM(is_finished_number) as total_finished
47 FROM {$funnel_table}
48 where applied_at > {$start_date} and funnel_id " . Analytics::target_id_condition( $this->target_id ) . " %d
49 GROUP BY `day` ORDER BY `day` ASC;", $this->target_id ),
50 ARRAY_A );
51 // phpcs:enable
52
53 $neat_data = [];
54
55 foreach ( $results as $result ) {
56 $conversion_rate = ( ( $result['total_finished'] * 100 ) / $result['total_started'] );
57
58 $neat_data[ $result['day'] ] = floatval( number_format( $conversion_rate, 2 ) );
59 }
60
61 $this->output = $neat_data;
62 }
63 }
64