PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 2.3.2
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v2.3.2
2.3.2 2.3.1 2.3.0 2.2.8 2.2.7 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.11.0 1.11.1 1.11.2 1.6 1.7 1.8 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 1.9.10 1.9.11 All 60 releases
merchant / inc / analytics / class-merchant-analytics-data-hooks.php

class-merchant-analytics-data-hooks.php in Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant 2.3.2, at inc/analytics/class-merchant-analytics-data-hooks.php

76 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 // Exit if accessed directly.
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 /**
9 * Class Merchant_Analytics_Data_Hooks
10 *
11 * This class is responsible for providing all hooks for analytics.
12 */
13 class Merchant_Analytics_Data_Hooks {
14 /**
15 * The single class instance.
16 *
17 * @var Merchant_Analytics_Data_Hooks|null
18 */
19 private static $instance = null;
20
21 /**
22 * @var Merchant_Analytics_DB_ORM
23 */
24 private $orm;
25
26 /**
27 * Constructor.
28 */
29 private function __construct() {
30 $this->orm = new Merchant_Analytics_DB_ORM();
31 }
32
33 /**
34 * Get the single class instance.
35 *
36 * @return Merchant_Analytics_Data_Hooks|null
37 */
38 public static function instance() {
39 if ( is_null( self::$instance ) ) {
40 self::$instance = new self();
41 }
42
43 return self::$instance;
44 }
45
46 /**
47 * Load WordPress hooks.
48 */
49 public function load_hooks() {
50 add_action( 'woocommerce_order_status_refunded', array( $this, 'delete_analytics_records_on_refund' ), 10, 2 );
51 }
52
53 /**
54 * Delete analytics records on refund.
55 *
56 * @param int $order_id Order ID.
57 * @param WC_Order $order Order object.
58 */
59 public function delete_analytics_records_on_refund( $order_id, $order ) {
60 if ( $order->get_status() === 'refunded' ) {
61 $event = $this->orm
62 ->where( 'event_type = %s', 'order' )
63 ->where( 'order_id = %d', $order_id )
64 ->first();
65 $this->orm->reset_query(); // Reset query after getting the data.
66
67 if ( ! empty( $event ) ) {
68 $event_id = $event['id'];
69 $this->orm->delete( $event_id );
70 }
71 }
72 }
73 }
74
75 Merchant_Analytics_Data_Hooks::instance()->load_hooks();
76