/var/www/html_uk/wp-content/plugins/automatewoo/includes/Triggers/File_Downloaded.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
<?php

namespace AutomateWoo;

defined'ABSPATH' ) || exit;

/**
 * Class Trigger_Downloadable_File_Downloaded.
 *
 * @since 5.6.6
 * @package AutomateWoo
 */
class Trigger_File_Downloaded extends Trigger_Abstract_Downloadable_Content {

    
/**
     * Load admin details.
     */
    
public function load_admin_details() {
        
$this->title       __'File Downloaded''automatewoo' );
        
$this->description __'This trigger fires after a file is downloaded.''automatewoo' );
        
parent::load_admin_details();
    }

    
/**
     * Register trigger hooks.
     */
    
public function register_hooks() {
        
add_action'woocommerce_download_product', array( $this'handle_file_downloaded' ), 10);
    }

    
/**
     * Handle file downloaded event.
     *
     * @param string $user_email  User Email address.
     * @param string $order_key   Order key.
     * @param int    $product_id  Product ID.
     * @param int    $user_id     User ID.
     * @param int    $download_id Download ID.
     * @param int    $order_id    Order ID.
     */
    
public function handle_file_downloaded$user_email$order_key$product_id$user_id$download_id$order_id ) {
        
$order    wc_get_order$order_id );
        
$product  wc_get_product$product_id );
        
$customer Customer_Factory::get_by_order$order );

        if ( ! 
$order || ! $product || ! $customer ) {
            return;
        }

        
// Maybe run workflows for given downloadable file.
        
$this->maybe_run_workflows$download_id$product$order$customer );
    }
}