PluginProbe
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster / 1.2.9
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster v1.2.9
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 / coupon / created-coupon.php

created-coupon.php in SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster 1.2.9, at includes/admin/components/analytics/coupon/created-coupon.php

59 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\Coupon;
4
5 use Sellkit\Admin\Components\Analytics;
6 use Sellkit\Admin\Components\Analytics\Analytics_Base;
7
8 defined( 'ABSPATH' ) || die();
9
10 /**
11 * Components class.
12 *
13 * @since 1.1.0
14 */
15 class Created_Coupon extends Analytics_Base {
16
17 /**
18 * Class constructor.
19 *
20 * @since 1.1.0
21 * @param int $rule_id Discount id.
22 */
23 public function __construct( $rule_id ) {
24 $this->target_id = $rule_id;
25
26 $this->set_coupons_details();
27 }
28
29 /**
30 * Set discount details.
31 *
32 * @since 1.1.0
33 */
34 public function set_coupons_details() {
35 global $wpdb;
36
37 $start_date = date( 'Y-m-d H:i:s', time() - ( 60 * 60 * 24 * Analytics::$date_range ) );
38 $posts_table = "{$wpdb->prefix}posts ";
39 $posts_meta_table = "{$wpdb->prefix}postmeta ";
40
41 // phpcs:disable
42 $coupons = $wpdb->get_results(
43 $wpdb->prepare( "SELECT count(p.id) as total, pm.meta_key, DATE_FORMAT( p.post_date_gmt, '%%b_%%d') as day FROM {$posts_table} AS p
44 LEFT JOIN {$posts_meta_table} pm ON pm.post_id = p.id AND pm.meta_key = 'sellkit_personalised_coupon_rule'
45 WHERE %s < p.post_date_gmt and p.post_type = 'shop_coupon' and pm.meta_value " . Analytics::target_id_condition( $this->target_id ) . " %s
46 GROUP BY DAY(p.post_date_gmt)", $start_date, $this->target_id ),
47 ARRAY_A );
48 // phpcs:enable
49
50 $neat_data = [];
51
52 foreach ( $coupons as $coupon ) {
53 $neat_data[ $coupon['day'] ] = intval( $coupon['total'] );
54 }
55
56 $this->output = $neat_data;
57 }
58 }
59