WC_Product_CSV_Exporter
extends WC_CSV_Batch_Exporter
in package
WC_Product_CSV_Exporter Class.
Table of Contents
- $column_names : array<string|int, mixed>
- Columns ids and names.
- $columns_to_export : array<string|int, mixed>
- List of columns to export, or empty for all.
- $delimiter : string
- The delimiter parameter sets the field delimiter (one character only).
- $enable_meta_export : bool
- Should meta be exported?
- $export_type : string
- Type of export used in filter names.
- $exported_row_count : int
- Number exported.
- $filename : string
- Filename to export to.
- $limit : int
- Batch limit.
- $page : int
- Page being exported
- $product_category_to_export : string
- Products belonging to what category should be exported.
- $product_types_to_export : array<string|int, mixed>
- Which product types are being exported.
- $row_data : array<string|int, mixed>
- Raw data to export.
- $total_rows : int
- Total rows to export.
- __construct() : mixed
- Constructor.
- enable_meta_export() : mixed
- Should meta be exported?
- escape_data() : string
- Escape a string to be used in a CSV context
- export() : mixed
- Do the export.
- format_data() : string
- Format and escape data ready for the CSV file.
- format_term_ids() : string
- Format term ids to names.
- generate_file() : mixed
- Generate the CSV file.
- get_column_names() : array<string|int, mixed>
- Return an array of supported column names and ids.
- get_columns_to_export() : array<string|int, mixed>
- Return an array of columns to export.
- get_default_column_names() : array<string|int, mixed>
- Return an array of columns to export.
- get_delimiter() : string
- Return the delimiter to use in CSV file
- get_file() : string
- Get the file contents.
- get_filename() : string
- Generate and return a filename.
- get_headers_row_file() : string
- Get the contents of the CSV headers row file. Defaults to the original known headers.
- get_limit() : int
- Get batch limit.
- get_page() : int
- Get page.
- get_percent_complete() : int
- Get total % complete.
- get_total_exported() : int
- Get count of records exported.
- is_column_exporting() : bool
- See if a column is to be exported or not.
- prepare_data_to_export() : mixed
- Prepare data for export.
- send_content() : mixed
- Set the export content.
- send_headers() : mixed
- Set the export headers.
- set_column_names() : mixed
- Set column names.
- set_columns_to_export() : mixed
- Set columns to export.
- set_filename() : mixed
- Set filename to export to.
- set_limit() : mixed
- Set batch limit.
- set_page() : mixed
- Set page.
- set_product_category_to_export() : void
- Product category to export
- set_product_types_to_export() : mixed
- Product types to export.
- export_column_headers() : string
- Export column headers in CSV format.
- export_row() : mixed
- Export rows to an array ready for the CSV.
- export_rows() : string
- Export rows in CSV format.
- filter_description_field() : string
- Filter description field for export.
- fputcsv() : mixed
- Write to the CSV file.
- generate_row_data() : array<string|int, mixed>
- Take a product and generate row data from it for export.
- get_column_value_backorders() : string
- Get backorders.
- get_column_value_category_ids() : string
- Get product_cat value.
- get_column_value_cross_sell_ids() : string
- Get cross_sell_ids value.
- get_column_value_download_expiry() : string
- Get download_expiry value.
- get_column_value_download_limit() : string
- Get download_limit value.
- get_column_value_grouped_products() : string
- Get grouped_products value.
- get_column_value_images() : string
- Get images value.
- get_column_value_low_stock_amount() : int|string
- Get low stock amount value.
- get_column_value_parent_id() : string
- Get parent_id value.
- get_column_value_published() : int
- Get published value.
- get_column_value_regular_price() : string
- Get formatted regular price.
- get_column_value_sale_price() : string
- Get formatted sale price.
- get_column_value_shipping_class_id() : string
- Get product_shipping_class value.
- get_column_value_stock() : string
- Get stock value.
- get_column_value_stock_status() : string
- Get stock status value.
- get_column_value_tag_ids() : string
- Get product_tag value.
- get_column_value_type() : string
- Get type value.
- get_column_value_upsell_ids() : string
- Get upsell_ids value.
- get_csv_data() : string
- Get CSV data for this export.
- get_data_to_export() : array<string|int, mixed>
- Get data that will be exported.
- get_file_path() : string
- Get file path to export to.
- get_headers_row_file_path() : string
- Get CSV headers row file path to export to.
- implode_values() : string
- Implode CSV cell values using commas by default, and wrapping values which contain the separator.
- prepare_attributes_for_export() : mixed
- Export attributes data.
- prepare_downloads_for_export() : mixed
- Export downloads.
- prepare_linked_products_for_export() : string
- Prepare linked products for export.
- prepare_meta_for_export() : mixed
- Export meta data.
- write_csv_data() : mixed
- Write data to the file.
Properties
$column_names
Columns ids and names.
protected
array<string|int, mixed>
$column_names
= array()
$columns_to_export
List of columns to export, or empty for all.
protected
array<string|int, mixed>
$columns_to_export
= array()
$delimiter
The delimiter parameter sets the field delimiter (one character only).
protected
string
$delimiter
= ','
$enable_meta_export
Should meta be exported?
protected
bool
$enable_meta_export
= alse
$export_type
Type of export used in filter names.
protected
string
$export_type
= 'product'
$exported_row_count
Number exported.
protected
int
$exported_row_count
= 0
$filename
Filename to export to.
protected
string
$filename
= 'wc-export.csv'
$limit
Batch limit.
protected
int
$limit
= 50
$page
Page being exported
protected
int
$page
= 1
$product_category_to_export
Products belonging to what category should be exported.
protected
string
$product_category_to_export
= array()
$product_types_to_export
Which product types are being exported.
protected
array<string|int, mixed>
$product_types_to_export
= array()
$row_data
Raw data to export.
protected
array<string|int, mixed>
$row_data
= array()
$total_rows
Total rows to export.
protected
int
$total_rows
= 0
Methods
__construct()
Constructor.
public
__construct() : mixed
Return values
mixed —enable_meta_export()
Should meta be exported?
public
enable_meta_export(bool $enable_meta_export) : mixed
Parameters
- $enable_meta_export : bool
-
Should meta be exported.
Tags
Return values
mixed —escape_data()
Escape a string to be used in a CSV context
public
escape_data(string $data) : string
Malicious input can inject formulas into CSV files, opening up the possibility for phishing attacks and disclosure of sensitive information.
Additionally, Excel exposes the ability to launch arbitrary commands through the DDE protocol.
Parameters
- $data : string
-
CSV field to escape.
Tags
Return values
string —export()
Do the export.
public
export() : mixed
Tags
Return values
mixed —format_data()
Format and escape data ready for the CSV file.
public
format_data(string $data) : string
Parameters
- $data : string
-
Data to format.
Tags
Return values
string —format_term_ids()
Format term ids to names.
public
format_term_ids(array<string|int, mixed> $term_ids, string $taxonomy) : string
Parameters
- $term_ids : array<string|int, mixed>
-
Term IDs to format.
- $taxonomy : string
-
Taxonomy name.
Tags
Return values
string —generate_file()
Generate the CSV file.
public
generate_file() : mixed
Tags
Return values
mixed —get_column_names()
Return an array of supported column names and ids.
public
get_column_names() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —get_columns_to_export()
Return an array of columns to export.
public
get_columns_to_export() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —get_default_column_names()
Return an array of columns to export.
public
get_default_column_names() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —get_delimiter()
Return the delimiter to use in CSV file
public
get_delimiter() : string
Tags
Return values
string —get_file()
Get the file contents.
public
get_file() : string
Tags
Return values
string —get_filename()
Generate and return a filename.
public
get_filename() : string
Return values
string —get_headers_row_file()
Get the contents of the CSV headers row file. Defaults to the original known headers.
public
get_headers_row_file() : string
Tags
Return values
string —get_limit()
Get batch limit.
public
get_limit() : int
Tags
Return values
int —get_page()
Get page.
public
get_page() : int
Tags
Return values
int —get_percent_complete()
Get total % complete.
public
get_percent_complete() : int
Tags
Return values
int —get_total_exported()
Get count of records exported.
public
get_total_exported() : int
Tags
Return values
int —is_column_exporting()
See if a column is to be exported or not.
public
is_column_exporting(string $column_id) : bool
Parameters
- $column_id : string
-
ID of the column being exported.
Tags
Return values
bool —prepare_data_to_export()
Prepare data for export.
public
prepare_data_to_export() : mixed
Tags
Return values
mixed —send_content()
Set the export content.
public
send_content(string $csv_data) : mixed
Parameters
- $csv_data : string
-
All CSV content.
Tags
Return values
mixed —send_headers()
Set the export headers.
public
send_headers() : mixed
Tags
Return values
mixed —set_column_names()
Set column names.
public
set_column_names(array<string|int, mixed> $column_names) : mixed
Parameters
- $column_names : array<string|int, mixed>
-
Column names array.
Tags
Return values
mixed —set_columns_to_export()
Set columns to export.
public
set_columns_to_export(array<string|int, mixed> $columns) : mixed
Parameters
- $columns : array<string|int, mixed>
-
Columns array.
Tags
Return values
mixed —set_filename()
Set filename to export to.
public
set_filename(string $filename) : mixed
Parameters
- $filename : string
-
Filename to export to.
Return values
mixed —set_limit()
Set batch limit.
public
set_limit(int $limit) : mixed
Parameters
- $limit : int
-
Limit to export.
Tags
Return values
mixed —set_page()
Set page.
public
set_page(int $page) : mixed
Parameters
- $page : int
-
Page Nr.
Tags
Return values
mixed —set_product_category_to_export()
Product category to export
public
set_product_category_to_export(string $product_category_to_export) : void
Parameters
- $product_category_to_export : string
-
Product category slug to export, empty string exports all.
Tags
Return values
void —set_product_types_to_export()
Product types to export.
public
set_product_types_to_export(array<string|int, mixed> $product_types_to_export) : mixed
Parameters
- $product_types_to_export : array<string|int, mixed>
-
List of types to export.
Tags
Return values
mixed —export_column_headers()
Export column headers in CSV format.
protected
export_column_headers() : string
Tags
Return values
string —export_row()
Export rows to an array ready for the CSV.
protected
export_row(array<string|int, mixed> $row_data, string $key, resource $buffer) : mixed
Parameters
- $row_data : array<string|int, mixed>
-
Data to export.
- $key : string
-
Column being exported.
- $buffer : resource
-
Output buffer.
Tags
Return values
mixed —export_rows()
Export rows in CSV format.
protected
export_rows() : string
Tags
Return values
string —filter_description_field()
Filter description field for export.
protected
filter_description_field(string $description) : string
Convert newlines to '\n'.
Parameters
- $description : string
-
Product description text to filter.
Tags
Return values
string —fputcsv()
Write to the CSV file.
protected
fputcsv(resource $buffer, array<string|int, mixed> $export_row) : mixed
Parameters
- $buffer : resource
-
Resource we are writing to.
- $export_row : array<string|int, mixed>
-
Row to export.
Tags
Return values
mixed —generate_row_data()
Take a product and generate row data from it for export.
protected
generate_row_data(WC_Product $product) : array<string|int, mixed>
Parameters
- $product : WC_Product
-
WC_Product object.
Return values
array<string|int, mixed> —get_column_value_backorders()
Get backorders.
protected
get_column_value_backorders(WC_Product $product) : string
Parameters
- $product : WC_Product
-
Product being exported.
Tags
Return values
string —get_column_value_category_ids()
Get product_cat value.
protected
get_column_value_category_ids(WC_Product $product) : string
Parameters
- $product : WC_Product
-
Product being exported.
Tags
Return values
string —get_column_value_cross_sell_ids()
Get cross_sell_ids value.
protected
get_column_value_cross_sell_ids(WC_Product $product) : string
Parameters
- $product : WC_Product
-
Product being exported.
Tags
Return values
string —get_column_value_download_expiry()
Get download_expiry value.
protected
get_column_value_download_expiry(WC_Product $product) : string
Parameters
- $product : WC_Product
-
Product being exported.
Tags
Return values
string —get_column_value_download_limit()
Get download_limit value.
protected
get_column_value_download_limit(WC_Product $product) : string
Parameters
- $product : WC_Product
-
Product being exported.
Tags
Return values
string —get_column_value_grouped_products()
Get grouped_products value.
protected
get_column_value_grouped_products(WC_Product $product) : string
Parameters
- $product : WC_Product
-
Product being exported.
Tags
Return values
string —get_column_value_images()
Get images value.
protected
get_column_value_images(WC_Product $product) : string
Parameters
- $product : WC_Product
-
Product being exported.
Tags
Return values
string —get_column_value_low_stock_amount()
Get low stock amount value.
protected
get_column_value_low_stock_amount(WC_Product $product) : int|string
Parameters
- $product : WC_Product
-
Product being exported.
Tags
Return values
int|string — Empty string if value not setget_column_value_parent_id()
Get parent_id value.
protected
get_column_value_parent_id(WC_Product $product) : string
Parameters
- $product : WC_Product
-
Product being exported.
Tags
Return values
string —get_column_value_published()
Get published value.
protected
get_column_value_published(WC_Product $product) : int
Parameters
- $product : WC_Product
-
Product being exported.
Tags
Return values
int —get_column_value_regular_price()
Get formatted regular price.
protected
get_column_value_regular_price(WC_Product $product) : string
Parameters
- $product : WC_Product
-
Product being exported.
Return values
string —get_column_value_sale_price()
Get formatted sale price.
protected
get_column_value_sale_price(WC_Product $product) : string
Parameters
- $product : WC_Product
-
Product being exported.
Return values
string —get_column_value_shipping_class_id()
Get product_shipping_class value.
protected
get_column_value_shipping_class_id(WC_Product $product) : string
Parameters
- $product : WC_Product
-
Product being exported.
Tags
Return values
string —get_column_value_stock()
Get stock value.
protected
get_column_value_stock(WC_Product $product) : string
Parameters
- $product : WC_Product
-
Product being exported.
Tags
Return values
string —get_column_value_stock_status()
Get stock status value.
protected
get_column_value_stock_status(WC_Product $product) : string
Parameters
- $product : WC_Product
-
Product being exported.
Tags
Return values
string —get_column_value_tag_ids()
Get product_tag value.
protected
get_column_value_tag_ids(WC_Product $product) : string
Parameters
- $product : WC_Product
-
Product being exported.
Tags
Return values
string —get_column_value_type()
Get type value.
protected
get_column_value_type(WC_Product $product) : string
Parameters
- $product : WC_Product
-
Product being exported.
Tags
Return values
string —get_column_value_upsell_ids()
Get upsell_ids value.
protected
get_column_value_upsell_ids(WC_Product $product) : string
Parameters
- $product : WC_Product
-
Product being exported.
Tags
Return values
string —get_csv_data()
Get CSV data for this export.
protected
get_csv_data() : string
Tags
Return values
string —get_data_to_export()
Get data that will be exported.
protected
get_data_to_export() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —get_file_path()
Get file path to export to.
protected
get_file_path() : string
Return values
string —get_headers_row_file_path()
Get CSV headers row file path to export to.
protected
get_headers_row_file_path() : string
Return values
string —implode_values()
Implode CSV cell values using commas by default, and wrapping values which contain the separator.
protected
implode_values(array<string|int, mixed> $values) : string
Parameters
- $values : array<string|int, mixed>
-
Values to implode.
Tags
Return values
string —prepare_attributes_for_export()
Export attributes data.
protected
prepare_attributes_for_export(WC_Product $product, array<string|int, mixed> &$row) : mixed
Parameters
- $product : WC_Product
-
Product being exported.
- $row : array<string|int, mixed>
-
Row being exported.
Tags
Return values
mixed —prepare_downloads_for_export()
Export downloads.
protected
prepare_downloads_for_export(WC_Product $product, array<string|int, mixed> &$row) : mixed
Parameters
- $product : WC_Product
-
Product being exported.
- $row : array<string|int, mixed>
-
Row being exported.
Tags
Return values
mixed —prepare_linked_products_for_export()
Prepare linked products for export.
protected
prepare_linked_products_for_export(array<string|int, int> $linked_products) : string
Parameters
- $linked_products : array<string|int, int>
-
Array of linked product ids.
Tags
Return values
string —prepare_meta_for_export()
Export meta data.
protected
prepare_meta_for_export(WC_Product $product, array<string|int, mixed> &$row) : mixed
Parameters
- $product : WC_Product
-
Product being exported.
- $row : array<string|int, mixed>
-
Row data.
Tags
Return values
mixed —write_csv_data()
Write data to the file.
protected
write_csv_data(string $data) : mixed
Parameters
- $data : string
-
Data.