Automattic\WooCommerce\Internal\ProductFeed\Feed
ProductWalker::walk
Walks through all products.
Метод класса: ProductWalker{}
Хуков нет.
Возвращает
int. The total number of products processed.
Использование
$ProductWalker = new ProductWalker(); $ProductWalker->walk( ?callable $callback ): int;
- ?callable $callback
- .
По умолчанию:null
Список изменений
| С версии 10.5.0 | Введена. |
Код ProductWalker::walk() ProductWalker::walk WC 10.5.2
public function walk( ?callable $callback = null ): int {
$progress = null;
// Instruct the feed to start.
$this->feed->start();
// Check how much memory is available at first.
$initial_available_memory = $this->memory_manager->get_available_memory();
do {
$result = $this->iterate( $this->query_args, $progress ? $progress->processed_batches + 1 : 1, $this->per_page );
$iterated = count( $result->products );
// Only done when the progress is not set. Will be modified otherwise.
if ( is_null( $progress ) ) {
$progress = WalkerProgress::from_wc_get_products_result( $result );
}
$progress->processed_items += $iterated;
++$progress->processed_batches;
if ( is_callable( $callback ) && $iterated > 0 ) {
$callback( $progress );
}
if ( $this->time_limit > 0 ) {
set_time_limit( $this->time_limit );
}
// We don't want to use more than half of the available memory at the beginning of the script.
$current_memory = $this->memory_manager->get_available_memory();
if ( $initial_available_memory - $current_memory >= $initial_available_memory / 2 ) {
$this->memory_manager->flush_caches();
}
} while (
// If `wc_get_products()` returns less than the batch size, it was the last page.
$iterated === $this->per_page
// For the cases where the above is true, make sure that we do not exceed the total number of pages.
&& $progress->processed_batches < $progress->total_batch_count
);
// Instruct the feed to end.
$this->feed->end();
return $progress->processed_items;
}