/var/www/html_uk/wp-content/plugins/automatewoo/includes/DatabaseUpdates/2.7.0.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
// phpcs:ignoreFile
/**
 * Update to 2.7 - ActiveCampaign changes
 */

if ( ! defined'ABSPATH' ) ) exit;


$workflows_query = new AutomateWoo\Workflow_Query();
$workflows_query->args['post_status'] = 'any';

$workflows $workflows_query->get_results();

foreach ( 
$workflows as $workflow ) {

    
/** @var $workflow AutomateWoo\Workflow */

    
$actions $workflow->get_meta'actions' );
    
$update false;

    if ( 
$actions ) foreach ( $actions as &$action ) {

        if ( empty( 
$action['action_name'] ) )
            continue;

        switch ( 
$action['action_name'] ) {

            case 
'add_user_to_active_campaign_list':
            case 
'active_campaign_add_tag':
                
$update true;

                if ( empty( 
$action['email'] ) ) $action['email'] = '{{ user.email }}';
                if ( empty( 
$action['first_name'] ) ) $action['first_name'] = '{{ user.firstname }}';
                if ( empty( 
$action['last_name'] ) ) $action['last_name'] = '{{ user.lastname }}';
                if ( empty( 
$action['phone'] ) ) $action['phone'] = '{{ user.billing_phone }}';

                break;

            case 
'active_campaign_remove_tag':

                
$update true;

                if ( empty( 
$action['email'] ) )  $action['email'] = '{{ user.email }}';

                break;
        }

        if ( 
$update ) {
            
$workflow->update_meta'actions'$actions );
        }
    }
}