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
<?php
namespace SIW\Batch;
use SIW\Plato\Import_FPL;
class Update_Free_Places extends Job {
protected $action = 'update_free_places';
protected $name = 'bijwerken vrije plaatsen';
protected $category = 'plato';
protected $schedule_job = false;
protected function has_free_places( $free_m, $free_f, $no_more_from ) {
$free_m = (int) $free_m;
$free_f = (int) $free_f;
return ( ( $free_m + $free_f ) > 0 && ( false === strpos( $no_more_from, 'NLD' ) ) ) ? 'yes' : 'no';
}
protected function select_data() {
$import = new Import_FPL;
$data = $import->run();
return $data;
}
protected function task( $item ) {
$args = [
'visibility' => 'visible',
'project_id' => $item['project_id'],
'return' => 'objects',
'limit' => -1,
];
$products = wc_get_products( $args );
if ( empty( $products ) ) {
return false;
}
$product = $products[0];
$new_free_places = $this->has_free_places( $item['free_m'], $item['free_f'], $item['no_more_from'] );
if ( $new_free_places !== $product->get_meta( 'freeplaces' ) ) {
$product->update_meta_data( 'freeplaces', $new_free_places );
$product->save();
$this->increment_processed_count();
}
return false;
}
}