/var/www/html_us/wp-content/plugins/checkout-for-woocommerce/includes/Admin/Pages/OrderBumps.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
<?php

namespace Objectiv\Plugins\Checkout\Admin\Pages;

/**
 * @link checkoutwc.com
 * @since 5.0.0
 * @package Objectiv\Plugins\Checkout\Admin\Pages
 * @author Clifton Griffin <[email protected]>
 */
class OrderBumps extends PageAbstract {
    protected 
$post_type_slug;
    protected 
$nonce_field  '_cfw_ob_nonce';
    protected 
$nonce_action 'cfw_save_ob_mb';
    protected 
$formatted_required_plans_list;
    protected 
$is_available;

    public function 
__constructstring $post_type_slugstring $formatted_required_plans_listbool $is_available ) {
        
parent::__constructcfw__'Order Bumps''checkout-wc' ), 'manage_options'null );

        
$this->post_type_slug                $post_type_slug;
        
$this->slug                          'edit.php?post_type=' $this->post_type_slug;
        
$this->formatted_required_plans_list $formatted_required_plans_list;
        
$this->is_available                  $is_available;
    }

    public function 
init() {
        
parent::init();

        
add_action'add_meta_boxes', array( $this'register_meta_boxes' ) );
        
add_action'save_post', array( $this'save_metaboxes' ) );
        
add_action'all_admin_notices', array( $this'output_with_wrap' ) );
        
add_action'all_admin_notices', array( $this'maybe_show_license_upgrade_splash' ) );

        
/**
         * Highlights Order Bumps submenu item when
         * on the New Order Bumps admin page
         */
        
add_filter'submenu_file', array( $this'maybe_highlight_order_bumps_submenu_item' ) );
    }

    public function 
get_url(): string {
        
$url admin_url$this->slug );

        return 
esc_url$url );
    }

    public function 
setup_menu() {
        global 
$submenu;

        
$stash_menu_item null;

        if ( empty( 
$submenuself::$parent_slug ] ) ) {
            return;
        }
        
        foreach ( (array) 
$submenuself::$parent_slug ] as $i => $item ) {
            if ( 
$this->slug === $item[2] ) {
                
$stash_menu_item $submenuself::$parent_slug ][ $i ];
                unset( 
$submenuself::$parent_slug ][ $i ] );
            }
        }

        if ( empty( 
$stash_menu_item ) ) {
            return;
        }

        
$submenuself::$parent_slug ][ $this->priority ] = $stash_menu_item;
    }

    public function 
register_meta_boxes() {
        
add_meta_box'cfw_order_bump_products_mb'cfw__'Display Conditions''checkout-wc' ), array( $this'render_products_meta_box' ), $this->post_type_slug );
        
add_meta_box'cfw_order_bump_offer_mb'cfw__'Offer''checkout-wc' ), array( $this'render_offer_meta_box' ), $this->post_type_slug );
    }

    
/**
     * @param \WP_Post $post
     */
    
public function render_products_meta_box\WP_Post $post ) {
        
$cfw_ob_display_for_options = array(
            
'all_products'        => cfw__'All Products''checkout-wc' ),
            
'specific_products'   => cfw__'Specific Products''checkout-wc' ),
            
'specific_categories' => cfw__'Specific Categories''checkout-wc' ),
        );

        
$cfw_ob_display_for_value get_post_meta$post->ID'cfw_ob_display_for'true );
        
$cfw_ob_any_product_value get_post_meta$post->ID'cfw_ob_any_product'true );

        
wp_nonce_field$this->nonce_action$this->nonce_field );
        
?>
        <table class="form-table">
            <tbody>
                <tr>
                    <th scope="row" valign="top">
                        <label for="cfw_ob_display_for">
                            <?php cfw_e'Display Offer For''checkout-wc' ); ?>
                        </label>
                    </th>
                    <td>
                        <select id="cfw_ob_display_for" name="cfw_ob_display_for">
                            <?php foreach ( $cfw_ob_display_for_options as $option_value => $option_label ) : ?>
                                <option value="<?php echo $option_value?><?php echo $option_value === $cfw_ob_display_for_value 'selected="selected"' ''?>>
                                    <?php echo $option_label?>
                                </option>
                            <?php endforeach; ?>
                        </select>
                    </td>
                </tr>
                <tr>
                    <th scope="row" valign="top">
                        <label for="cfw_ob_products">
                            <?php cfw_e'Products''checkout-wc' ); ?>
                        </label>
                    </th>
                    <td>
                        <select class="wc-product-search" multiple="multiple" style="width: 50%;" id="cfw_ob_products" name="cfw_ob_products[]" data-placeholder="<?php cfw_esc_attr_e'Search for a product&hellip;''woocommerce' ); ?>" data-action="woocommerce_json_search_products_and_variations">
                            <?php
                            $product_ids 
get_post_meta$post->ID'cfw_ob_products'true );

                            foreach ( 
$product_ids as $product_id ) {
                                
$product wc_get_product$product_id );
                                if ( 
is_object$product ) ) {
                                    echo 
'<option value="' esc_attr$product_id ) . '"' selectedtruetruefalse ) . '>' esc_htmlwp_strip_all_tags$product->get_formatted_name() ) ) . '</option>';
                                }
                            }
                            
?>
                        </select>
                    </td>
                </tr>
                <tr>
                    <th scope="row" valign="top">
                        <label for="cfw_ob_products">
                            <?php cfw_e'Categories''checkout-wc' ); ?>
                        </label>
                    </th>
                    <td>
                        <select class="wc-category-search" multiple="multiple" style="width: 50%;" id="cfw_ob_categories" name="cfw_ob_categories[]" data-placeholder="<?php cfw_esc_attr_e'Search for a category&hellip;''woocommerce' ); ?>" data-allow_clear="true">
                            <?php
                            $category_slugs 
get_post_meta$post->ID'cfw_ob_categories'true );

                            foreach ( 
$category_slugs as $category_slug ) {
                                
$category get_term_by'slug'$category_slug'product_cat' );

                                if ( 
$category ) {
                                    echo 
'<option value="' esc_attr$category_slug ) . '"' selectedtruetruefalse ) . '>' esc_htmlwp_strip_all_tags$category->name ) ) . '</option>';
                                }
                            }
                            
?>
                        </select>
                    </td>
                </tr>
                <tr>
                    <th scope="row" valign="top">
                        <label for="cfw_ob_any_product">
                            <?php cfw_e'Condition''checkout-wc' ); ?>
                        </label>
                    </th>
                    <td>
                        <input type="hidden" name="cfw_ob_any_product" value="yes" />
                        <input type="checkbox" class="cfw-checkbox" name="cfw_ob_any_product" id="cfw_ob_any_product" value="no" <?php echo 'no' === $cfw_ob_any_product_value 'checked' ''?> />

                        <label class="cfw-checkbox-label" for="cfw_ob_any_product">
                            <?php cfw_e'Apply if all matching products are in the cart.''checkout-wc' ); ?>
                        </label>

                        <p>
                            <span class="description">
                                <?php cfw_e'If checked, all products above must be in the cart. If unchecked order bump will show if any of the above products is in the cart.''checkout-wc' ); ?>
                            </span>
                        </p>
                    </td>
                </tr>
                <tr>
                    <th scope="row" valign="top">
                        <label for="cfw_ob_display_location">
                            <?php cfw_e'Display Location''checkout-wc' ); ?>
                        </label>
                    </th>
                    <td>
                        <p>
                            <?php
                            $cfw_ob_display_location_value 
get_post_meta$post->ID'cfw_ob_display_location'true );
                            
$default_value                 'below_cart_items';

                            
$display_location_options = array(
                                
'below_cart_items' => 'Below Cart Items',
                                
'above_terms_and_conditions' => 'Above Terms and Conditions',
                            );
                            foreach ( 
$display_location_options as $option_value => $option_label ) :
                                
?>
                                <label>
                                    <input type="radio" name="cfw_ob_display_location" value="<?php echo $option_value?><?php echo $option_value === $cfw_ob_display_location_value || ( empty( $cfw_ob_display_location_value ) && $option_value === $default_value ) ? 'checked' ''?> /> <?php echo $option_label?><br />
                                </label>
                            <?php endforeach; ?>
                        </p>

                        <p class="description">
                            <?php cfw_e'Where to display order bumps. Order bumps will always display above terms and conditions on mobile.''checkout-wc' ); ?>
                        </p>
                    </td>
                </tr>
            </tbody>
        </table>
        <?php
    
}

    
/**
     * @param \WP_Post $post
     */
    
public function render_offer_meta_box\WP_Post $post ) {
        
$cfw_ob_discount_type_options = array(
            
'percent' => 'Percent Off',
            
'amount'  => 'Amount Off',
        );

        
$cfw_ob_discount_type_default 'percent';

        
$cfw_ob_discount_type_value get_post_meta$post->ID'cfw_ob_discount_type'true );
        
$cfw_ob_offer_product       get_post_meta$post->ID'cfw_ob_offer_product'true );
        
$cfw_ob_offer_discount      get_post_meta$post->ID'cfw_ob_offer_discount'true );
        
$cfw_ob_offer_language      get_post_meta$post->ID'cfw_ob_offer_language'true );
        
$cfw_ob_offer_description   get_post_meta$post->ID'cfw_ob_offer_description'true );
        
$cfw_ob_upsell_value        get_post_meta$post->ID'cfw_ob_upsell'true );

        if ( empty( 
$cfw_ob_offer_language ) ) {
            
$cfw_ob_offer_language 'Yes! Please add this offer to my order';
        }

        if ( empty( 
$cfw_ob_offer_description ) ) {
            
$cfw_ob_offer_description 'Limited time offer! Get an EXCLUSIVE discount right now! Click the checkbox above to add this product to your order now.';
        }
        
?>
        <table class="form-table">
            <tbody>
                <tr>
                    <th scope="row" valign="top">
                        <label for="cfw_ob_offer_product">
                            <?php cfw_e'Product''checkout-wc' ); ?>
                        </label>
                    </th>
                    <td>
                        <select class="wc-product-search" style="width: 50%;" id="cfw_ob_offer_product" data-exclude_type="variable" name="cfw_ob_offer_product" data-placeholder="<?php cfw_esc_attr_e'Search for a product&hellip;''woocommerce' ); ?>" data-action="woocommerce_json_search_products_and_variations">
                            <?php
                            $product_ids 
= array( $cfw_ob_offer_product );

                            foreach ( 
$product_ids as $product_id ) {
                                
$product wc_get_product$product_id );
                                if ( 
is_object$product ) ) {
                                    echo 
'<option value="' esc_attr$product_id ) . '"' selectedtruetruefalse ) . '>' esc_htmlwp_strip_all_tags$product->get_formatted_name() ) ) . '</option>';
                                }
                            }
                            
?>
                        </select>
                    </td>
                </tr>

                <tr>
                    <th scope="row" valign="top">
                        <label for="cfw_ob_any_product">
                            <?php cfw_e'Upsell''checkout-wc' ); ?>
                        </label>
                    </th>
                    <td>
                        <input type="hidden" name="cfw_ob_upsell" value="no" />
                        <input type="checkbox" class="cfw-checkbox" name="cfw_ob_upsell" id="cfw_ob_upsell" value="yes" <?php echo 'yes' === $cfw_ob_upsell_value 'checked' ''?> />

                        <label class="cfw-checkbox-label" for="cfw_ob_upsell">
                            <?php cfw_e'Replace cart product with offer product when this order bump is taken.''checkout-wc' ); ?>
                        </label>

                        <p>
                            <span class="description">
                                <?php cfw_e'Requirements: <i>Display Offer For</i> must be set to <i>Specific Products</i>. Only one product should be defined in <i>Products</i> list.''checkout-wc' ); ?>
                            </span>
                        </p>
                    </td>
                </tr>

                <tr>
                    <th scope="row" valign="top">
                        <label for="cfw_ob_discount_type">
                            <?php cfw_e'Discount Type''checkout-wc' ); ?>
                        </label>
                    </th>
                    <td>
                        <p>
                            <?php foreach ( $cfw_ob_discount_type_options as $option_value => $option_label ) : ?>
                                <label>
                                    <input type="radio" name="cfw_ob_discount_type" value="<?php echo $option_value?><?php echo $option_value === $cfw_ob_discount_type_value || ( empty( $cfw_ob_discount_type_value ) && $option_value === $cfw_ob_discount_type_default ) ? 'checked' ''?> /> <?php echo $option_label?><br />
                                </label>
                            <?php endforeach; ?>
                        </p>

                        <p class="description">
                            <?php cfw_e'Amount Off: Remove fixed amount from the product price.''checkout-wc' ); ?>
                        </p>

                        <p class="description">
                            <?php cfw_e'Percent Off: Discount product by specified percentage.''checkout-wc' ); ?>
                        </p>
                    </td>
                </tr>

                <tr>
                    <th scope="row" valign="top">
                        <label for="cfw_ob_offer_discount">
                            <?php cfw_e'Discount''checkout-wc' ); ?>
                        </label>
                    </th>
                    <td>
                        <input type="text" value="<?php echo esc_attr$cfw_ob_offer_discount ); ?>" name="cfw_ob_offer_discount" />
                    </td>
                </tr>

                <tr>
                    <th scope="row" valign="top">
                        <label for="cfw_ob_offer_language">
                            <?php cfw_e'Offer Language''checkout-wc' ); ?>
                        </label>
                    </th>
                    <td>
                        <input size="60" type="text" value="<?php echo esc_attr$cfw_ob_offer_language ); ?>" name="cfw_ob_offer_language" />

                        <p class="description">
                            <?php cfw_e'Example: Yes! Please add this offer to my order''checkout-wc' ); ?>
                        </p>
                    </td>
                </tr>

                <tr>
                    <th scope="row" valign="top">
                        <label for="cfw_ob_offer_description">
                            <?php cfw_e'Offer Description''checkout-wc' ); ?>
                        </label>
                    </th>
                    <td>
                        <textarea cols="60" rows="6" type="text" name="cfw_ob_offer_description"><?php echo esc_attr$cfw_ob_offer_description ); ?></textarea>

                        <p class="description">
                            Example: Limited time offer! Get an EXCLUSIVE discount right now! Click the checkbox above to add this product to your order now.
                        </p>
                    </td>
                </tr>
            </tbody>
        </table>
        <?php
    
}

    
/**
     * @param int $post_id
     */
    
public function save_metaboxesint $post_id ) {
        
$nonce_name $_POST$this->nonce_field ] ?? '';

        if ( ! 
wp_verify_nonce$nonce_name$this->nonce_action ) ) {
            return;
        }

        if ( ! 
current_user_can'edit_post'$post_id ) ) {
            return;
        }

        if ( 
wp_is_post_autosave$post_id ) ) {
            return;
        }

        if ( 
wp_is_post_revision$post_id ) ) {
            return;
        }

        
// Display Conditions
        
update_post_meta$post_id'cfw_ob_display_for'$_POST['cfw_ob_display_for'] );
        
update_post_meta$post_id'cfw_ob_products'$_POST['cfw_ob_products'] );
        
update_post_meta$post_id'cfw_ob_categories'$_POST['cfw_ob_categories'] );
        
update_post_meta$post_id'cfw_ob_any_product'$_POST['cfw_ob_any_product'] );
        
update_post_meta$post_id'cfw_ob_display_location'$_POST['cfw_ob_display_location'] );

        
// Offer Fields
        
update_post_meta$post_id'cfw_ob_discount_type'$_POST['cfw_ob_discount_type'] );
        
update_post_meta$post_id'cfw_ob_offer_product'$_POST['cfw_ob_offer_product'] );
        
update_post_meta$post_id'cfw_ob_offer_discount'$_POST['cfw_ob_offer_discount'] );
        
update_post_meta$post_id'cfw_ob_offer_language'$_POST['cfw_ob_offer_language'] );
        
update_post_meta$post_id'cfw_ob_offer_description'$_POST['cfw_ob_offer_description'] );
        
update_post_meta$post_id'cfw_ob_upsell'$_POST['cfw_ob_upsell'] );
    }

    public function 
is_current_page(): bool {
        global 
$post;

        if ( isset( 
$_GET['post_type'] ) && $this->post_type_slug === $_GET['post_type'] ) {
            return 
true;
        }

        if ( 
$post && $this->post_type_slug === $post->post_type ) {
            return 
true;
        }

        return 
false;
    }

    
/**
     * The admin page wrap
     *
     * @since 1.0.0
     * @access public
     */
    
public function output_with_wrap() {
        if ( ! 
$this->is_current_page() ) {
            return;
        }
        
?>
        <div class="cfw-admin-page-heading">
            <h1>
                <span><?php echo cfw__'CheckoutWC''checkout-wc' ); ?> &gt; </span><?php echo $this->title?>
            </h1>
        </div>

        <div class="cfw-admin-content-wrap cfw-admin-screen-<?php echo sanitize_title_with_dashes$this->title ); ?>">
            <script type="text/javascript">!function(e,t,n){function a(){var e=t.getElementsByTagName("script")[0],n=t.createElement("script");n.type="text/javascript",n.async=!0,n.src="https://beacon-v2.helpscout.net",e.parentNode.insertBefore(n,e)}if(e.Beacon=n=function(t,n,a){e.Beacon.readyQueue.push({method:t,options:n,data:a})},n.readyQueue=[],"complete"===t.readyState)return a();e.attachEvent?e.attachEvent("onload",a):e.addEventListener("load",a,!1)}(window,document,window.Beacon||function(){});</script>
            <script type="text/javascript">window.Beacon('init', '355a5a54-eb9d-4b64-ac5f-39c95644ad36')</script>
        </div>
        <?php
    
}

    public function 
maybe_show_license_upgrade_splash() {
        if ( 
$this->is_current_page() && ! $this->is_available ) {
            echo 
$this->get_upgrade_required_notice$this->formatted_required_plans_list );
        }
    }

    
/**
     * @param mixed $submenu_file
     * @return mixed
     */
    
public function maybe_highlight_order_bumps_submenu_item$submenu_file ) {
        
$post_type $this->post_type_slug;

        if ( 
stripos$_SERVER['REQUEST_URI'], "post-new.php?post_type=$post_type) !== false ) {
            return 
$this->get_slug();
        }

        return 
$submenu_file;
    }

    public function 
output() {}
}