/var/www/html/wp-content/plugins/dream-team/admin/templates/upsell-template.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
<?php 
$product_categories 
get_terms'product_cat', array(
    
'orderby'    => 'name',
    
'order'      => 'asc',
    
'hide_empty' => true
));

?>
<select id="drt-product-teams">
    <option value="none">- Select Teams Data -</option>
    <option value="MLB">MLB Teams Data</option>
    <option value="NFL">NFL Teams Data</option>
    <option value="NBA">NBA Teams Data</option>
</select>

<select id="drt-product-cat">
    <option value="none">- Select Category -</option>
    <?php
    
foreach($product_categories as $category):
    
?>
    <option value="<?php echo esc_html($category->slug);?>"><?php echo esc_html($category->name);?></option>
    <?php
    
endforeach;
    
?>
</select>
<button class="button button-primary drt-auto-upsell-button">Run Auto Set Up-sell</button>
<label for="drt-upsell-none-overrite" style="margin-left: 20px;"><input type="checkbox" id="drt-upsell-none-overrite" value="1" > Bỏ qua SP đã có Up-sell list?</label>

<h4 style="margin-top: 50px; font-size: 110%;">=== Logs === <span class="product-effected" data-count="0"></span></h4>
<ol class="kd-logs"></ol>

<script>
    (function($){
        function addUpsell(page, catSlug, catTeams, noneOw) {
            $.ajax({
                url: ajaxurl + '?action=drt_get_product&page='+page + '&slug=' + catSlug + '&teams=' + catTeams + '&none_ow=' + noneOw,
                type: 'GET',
                dataType: 'json',
                beforeSend: function() {
                    $('.drt-auto-upsell-button').prop('disabled', true);
                },
                success: function(data) {
                    var countEl = $('.product-effected');
                    var count = parseInt(countEl.data('count'));
                    count += parseInt(data.count);
                    countEl.data('count', count).text('(Total: ' + count + ' products)');

                    $('.kd-logs').append("<li>-------------------------------------------------------- | Page: " + page + ' - (' + data.added.length + '/' + data.count + ')</li>');
                    data.added.forEach(function(item) {
                        var html = '<li>   - ' + item.html + ' | Term: ' + item.term + '</li>';
                        $('.kd-logs').append(html);
                    });
                    if (parseInt(data.count) == 20 ) {
                        addUpsell(page+1, catSlug, catTeams, noneOw)
                    } else {
                        $('.drt-auto-upsell-button').prop('disabled', false);
                    }
                }
            });
        }
        $('.drt-auto-upsell-button').on('click', function(e) {
            e.preventDefault();
            var noneOw = $('#drt-upsell-none-overrite').is(":checked") ? 'yes': 'no';
            var catSlug = $('#drt-product-cat').val();
            var catTeams = $('#drt-product-teams').val();
            $('.kd-logs').html('');
            $('.product-effected').html('');
            if (catSlug !== 'none' && catTeams !== 'none') {
                addUpsell(1, catSlug, catTeams, noneOw);
            }
        });
        
    })(jQuery)
</script>