-
Notifications
You must be signed in to change notification settings - Fork 0
/
recount_terms.php
71 lines (49 loc) · 1.74 KB
/
recount_terms.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
<?php
/**
* Plugin Name: Recount Product Category
* Description: Recounter counts products categories for WooCommerce (trg_wc_recount_term)
*/
class trg_wc_recount_term {
public function __construct() {
add_action('admin_menu', function () {
add_management_page(
$page_title = 'Recount Product Category',
$menu_title = 'Recount Product Category',
$capability = 'manage_options',
$menu_slug = 'trg_wc_recount_term_ui',
$function = [$this, 'admin_ui_callback']
);
});
}
public function admin_ui_callback(){
$args = array(
'taxonomy' => 'product_cat',
'hide_empty' => false,
);
$terms = get_terms( $args );
//var_dump($terms);
foreach ($terms as $term) {
echo '<pre>';
//var_dump($term);
echo 'slug: ' . $term->slug . '<br/>';
echo 'term_id: ' . $term->term_id . '<br/>';
echo 'term_taxonomy_id: ' . $term->term_taxonomy_id . '<br/>';
echo 'count: ' . $term->count . '<br/>';
echo '</pre>';
//_wc_term_recount($term, $taxonomy = 'product_cat', $callback = true, false);
$args_new = [
'slug' => $term->slug,
'count' => "33",
];
$tn = wp_update_term( $term->term_id, $taxonomy = product_cat, $args_new );
echo 'Обновлен тремин: ' . $tn['term_id'] . '<br/>';
//var_dump($tn);
echo '<hr>';
}
?>
<div class="trg_wc_recount_term_wrapper">
</div>
<?php
}
}
$the_trg_wc_recount_term = new trg_wc_recount_term;