/var/www/html_uk/wp-content/plugins/automatewoo/includes/Frontend.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php
// phpcs:ignoreFile

namespace AutomateWoo;

/**
 * Checkout hooks class.
 *
 * Only loads on the checkout page.
 *
 * @since 4.0
 */
class Frontend {


    
/**
     * @return string
     */
    
static function get_communication_page_legal_text() {
        
$text Options::communication_page_legal_text();

        if ( 
function_exists'wc_replace_policy_page_link_placeholders' ) ) {
            
$text wc_replace_policy_page_link_placeholders$text );
        }

        
$find_replace = [
            
'[terms]' => '',
            
'[privacy_policy]' => '',
        ];

        
$text str_replacearray_keys$find_replace ), array_values$find_replace ), $text );

        return 
apply_filters'automatewoo/communication_page/legal_text'$text );
    }


    
/**
     * @return Customer|false
     */
    
static function get_current_customer() {
        if ( 
is_user_logged_in() ) {
            return 
Customer_Factory::get_by_user_idget_current_user_id() );
        }

        return 
false;
    }


    
/**
     * If $customer is set the customer key will be added to the link.
     *
     * @param Customer|false $customer
     * @param bool|string $intent
     * @return bool|string
     */
    
static function get_communication_page_permalink$customer false$intent false ) {
        if ( ! 
$url get_permalinkOptions::communication_page_id() ) ) {
            return 
false;
        }

        
$args = [];

        if ( 
$customer ) {
            
$args['customer_key'] = urlencode$customer->get_key() );
        }

        if ( 
$intent ) {
            
$args['intent'] = urlencode$intent );
        }

        
// SEMGREP WARNING EXPLANATION
        // URL is escaped. However, Semgrep only considers esc_url as valid.
        
return esc_url_rawadd_query_arg$args$url ) );
    }


    
/**
     * Only shows when using optin mode
     */
    
static function output_signup_optin_checkbox() {
        if ( ! 
Options::optin_enabled() || ! Options::account_optin_enabled() ) {
            return;
        }

        
aw_get_template'optin-checkbox.php' );
    }


    
/**
     * Only shows when using optin mode
     */
    
static function output_checkout_optin_checkbox() {
        if ( ! 
Options::optin_enabled() || ! Options::checkout_optin_enabled() ) {
            return;
        }

        
$customer Frontend::get_current_customer();

        if ( 
$customer && $customer->get_is_subscribed() ) {
            return; 
// customer already opted in
        
}

        
aw_get_template'optin-checkbox.php' );
    }


    
/**
     * @param int $order_id
     */
    
static function process_checkout_optin$order_id ) {
        if ( ! 
Options::optin_enabled() || ! Options::checkout_optin_enabled() ) {
            return;
        }

        if ( ! 
$order wc_get_order$order_id ) ) {
            return;
        }

        if ( ! isset( 
$_POST'automatewoo_optin' ] ) ) {
            return;
        }

        
$customer Customer_Factory::get_by_order$order );
        if ( ! 
$customer ) {
            return;
        }

        
$customer->opt_in();
    }

    
/**
     * @param \WC_Order $order
     * @param \WP_Request $request
     */
    
static function process_checkout_block_optin$order$request ) {
        if ( ! 
Options::optin_enabled() || ! Options::checkout_optin_enabled() ) {
            return;
        }

        if ( ! 
$order ) {
            return;
        }

        if ( empty( 
$request['extensions']['automatewoo'][ 'optin' ] ) ) {
            return;
        }

        
$customer Customer_Factory::get_by_order$order );
        if ( ! 
$customer ) {
            return;
        }

        
$customer->opt_in();
    }


    
/**
     * @param int $user_id
     */
    
static function process_account_signup_optin$user_id ) {
        if ( ! 
Options::optin_enabled() || ! Options::account_optin_enabled() ) {
            return;
        }

        if ( ! isset( 
$_POST['woocommerce-register-nonce'] ) ) {
            return; 
// signup not from registration form
        
}

        if ( isset( 
$_POST'automatewoo_optin' ] ) ) {
            
$customer Customer_Factory::get_by_user_id$user_id );
            
$customer->opt_in();
        }
    }


}