/var/www/html_uk/wp-content/plugins/automatewoo/admin/dashboard-widgets/chart-conversions.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php

namespace AutomateWoo;

defined'ABSPATH' ) || exit;

/**
 * Dashboard_Widget_Chart_Conversions class.
 */
class Dashboard_Widget_Chart_Conversions extends Dashboard_Widget_Chart {

    
/**
     * Widget's ID
     *
     * @var string
     */
    
public $id 'chart-conversions';

    
/**
     * Report page id to be used for "view report" link.
     *
     * @var string
     */
    
protected $report_page_id 'conversions';

    
/**
     * Define whether a chart widget represents monetary data or some other type of metric.
     *
     * @var bool
     */
    
public $is_currency true;

    
/**
     * Number of conversions
     *
     * @var int
     */
    
public $conversion_count 0;

    
/**
     * Total monetary value of conversions
     *
     * @var int
     */
    
public $conversion_total 0;


    
/**
     * Load the chart's data.
     *
     * @return array
     */
    
protected function load_data() {
        
$conversions       $this->controller->get_conversions();
        
$conversions_clean = [];

        foreach ( 
$conversions as $order ) {
            
$conversions_clean[] = (object) [
                
'date'  => $order->get_date_created(),
                
'total' => $order->get_total(),
            ];

            ++
$this->conversion_count;
            
$this->conversion_total += $order->get_total();
        }

        return [ 
array_values$this->prepare_chart_data$conversions_clean'date''total'$this->get_interval(), 'day' ) ) ];
    }

    
/**
     * Output the widget content.
     */
    
protected function output_content() {
        if ( ! 
$this->date_to || ! $this->date_from ) {
            return;
        }

        
$this->render_js();
        
?>

        <div class="automatewoo-dashboard-chart">
            <div class="automatewoo-dashboard-chart__header">

                <div class="automatewoo-dashboard-chart__header-group">
                    <div class="automatewoo-dashboard-chart__header-figure"><?php echo wp_kses_postwc_price$this->conversion_total ) ); ?></div>
                    <div class="automatewoo-dashboard-chart__header-text">
                        <span class="automatewoo-dashboard-chart__legend automatewoo-dashboard-chart__legend--blue"></span>
                        <?php esc_html_e'conversion revenue''automatewoo' ); ?>
                    </div>
                </div>

                <div class="automatewoo-dashboard-chart__header-group">
                    <div class="automatewoo-dashboard-chart__header-figure"><?php echo esc_html$this->conversion_count ); ?></div>
                    <div class="automatewoo-dashboard-chart__header-text"><?php esc_html_e'conversions''automatewoo' ); ?></div>
                </div>

                <?php $this->output_report_arrow_link(); ?>
            </div>

            <div class="automatewoo-dashboard-chart__tooltip"></div>

            <div id="automatewoo-dashboard-<?php echo esc_attr$this->get_id() ); ?>" class="automatewoo-dashboard-chart__flot"></div>
        </div>

        <?php
    
}
}

return new 
Dashboard_Widget_Chart_Conversions();