inc/analytics
class-merchant-analytics-data-ajax.php
12.5 KB
1 month ago
class-merchant-analytics-data-hooks.php
1.5 KB
1 month ago
class-merchant-analytics-data-provider.php
21.0 KB
1 month ago
class-merchant-analytics-data-reports.php
33.6 KB
1 month ago
class-merchant-analytics-db-orm.php
15.5 KB
1 month ago
class-merchant-analytics-logger.php
4.7 KB
1 month ago
class-merchant-analytics-data-hooks.php in Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant 2.3.1, at inc/analytics/class-merchant-analytics-data-hooks.php
| 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 |