WC_Product_CSV_Exporter::prepare_data_to_export()
Prepare data for export.
Method of the class: WC_Product_CSV_Exporter{}
Hooks from the method
Return
null
. Nothing (null).
Usage
$WC_Product_CSV_Exporter = new WC_Product_CSV_Exporter(); $WC_Product_CSV_Exporter->prepare_data_to_export();
Changelog
Since 3.1.0 | Introduced. |
WC_Product_CSV_Exporter::prepare_data_to_export() WC Product CSV Exporter::prepare data to export code WC 9.3.3
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 ); } } } }