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
<?php
namespace SIW\Batch;
class Count_Workcamps extends Job {
protected $action = 'count_workcamps';
protected $name = 'tellen groepsprojecten';
protected $category = 'groepsprojecten';
protected function select_data() {
$taxonomies = [
'product_cat',
'pa_land',
'pa_maand',
];
$data = [];
foreach ( $taxonomies as $taxonomy ) {
$terms = get_terms( $taxonomy, [ 'hide_empty' => true ] );
foreach ( $terms as $term ) {
$data[] = [ 'taxonomy' => $taxonomy, 'term_slug' => $term->slug, 'term_id'=> $term->term_id ];
}
}
return $data;
}
protected function task( $term ) {
$tax_query = [
[
'taxonomy' => $term['taxonomy'],
'field' => 'slug',
'terms' => $term['term_slug'],
],
];
$products = wc_get_products(
[
'status' => 'publish',
'limit' => -1,
'return' => 'ids',
'visibility' => 'visible',
'tax_query' => $tax_query,
]
);
$count = count( $products );
update_term_meta( $term['term_id'], 'project_count', $count );
$this->increment_processed_count();
return false;
}
}