WC_Product_CSV_Exporter::prepare_data_to_export()
Prepare data for export.
Description Description
Source Source
File: includes/export/class-wc-product-csv-exporter.php
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 seperately 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 );
}
}
}
}
Changelog Changelog
| Version | Description |
|---|---|
| 3.1.0 | Introduced. |