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
<?php
namespace SIW\Batch;
class Update_Workcamp_Visibility extends Job {
protected $action = 'update_workcamp_visibility';
protected $name = 'bijwerken zichtbaarheid groepsprojecten';
protected $category = 'groepsprojecten';
const MIN_DAYS_BEFORE_START = 3;
protected function select_data() {
$args = [
'return' => 'ids',
'limit' => -1,
];
$products = wc_get_products( $args );
return $products;
}
protected function task( $product_id ) {
$product = wc_get_product( $product_id );
if ( false === $product ) {
return false;
}
$country = siw_get_country( $product->get_meta( 'country' ) );
$new_visibility = 'visible';
if (
'no' === $product->get_meta( 'freeplaces' )
||
false === $country
||
! $country->is_allowed()
||
date( 'Y-m-d', time() + ( self::MIN_DAYS_BEFORE_START * DAY_IN_SECONDS ) ) >= $product->get_meta( 'start_date' )
) {
$new_visibility = 'hidden';
}
if ( $new_visibility !== $product->get_catalog_visibility() ) {
$product->set_catalog_visibility( $new_visibility );
if ( 'hidden' === $new_visibility ) {
$product->set_featured( false );
}
$product->save();
$this->increment_processed_count();
}
return false;
}
}