WC_Product_CSV_Exporter::prepare_data_to_export()publicWC 3.1.0

Prepare data for export.

Метод класса: WC_Product_CSV_Exporter{}

Возвращает

null. Ничего (null).

Использование

$WC_Product_CSV_Exporter = new WC_Product_CSV_Exporter();
$WC_Product_CSV_Exporter->prepare_data_to_export();

Список изменений

С версии 3.1.0 Введена.

Код WC_Product_CSV_Exporter::prepare_data_to_export() WC 8.7.0

public function prepare_data_to_export() {
	$args = array(
		'status'   => array( 'private', 'publish', 'draft', 'future', 'pending' ),
		'type'     => $this->product_types_to_export,
		'limit'    => $this->get_limit(),
		'page'     => $this->get_page(),
		'orderby'  => array(
			'ID' => 'ASC',
		),
		'return'   => 'objects',
		'paginate' => true,
	);

	if ( ! empty( $this->product_category_to_export ) ) {
		$args['category'] = $this->product_category_to_export;
	}
	$products = wc_get_products( apply_filters( "woocommerce_product_export_{$this->export_type}_query_args", $args ) );

	$this->total_rows  = $products->total;
	$this->row_data    = array();
	$variable_products = array();

	foreach ( $products->products as $product ) {
		// Check if the category is set, this means we need to fetch variations separately as they are not tied to a category.
		if ( ! empty( $args['category'] ) && $product->is_type( 'variable' ) ) {
			$variable_products[] = $product->get_id();
		}

		$this->row_data[] = $this->generate_row_data( $product );
	}

	// If a category was selected we loop through the variations as they are not tied to a category so will be excluded by default.
	if ( ! empty( $variable_products ) ) {
		foreach ( $variable_products as $parent_id ) {
			$products = wc_get_products(
				array(
					'parent' => $parent_id,
					'type'   => array( 'variation' ),
					'return' => 'objects',
					'limit'  => -1,
				)
			);

			if ( ! $products ) {
				continue;
			}

			foreach ( $products as $product ) {
				$this->row_data[] = $this->generate_row_data( $product );
			}
		}
	}
}