WooCommerce Code Reference

Search results

WC_Product_CSV_Exporter extends WC_CSV_Batch_Exporter

WC_Product_CSV_Exporter Class.

Table of Contents

$export_type Type of export used in filter names. string
$enable_meta_export Should meta be exported? bool
$product_types_to_export Which product types are being exported. array
$product_category_to_export Products belonging to what category should be exported. string
$page Page being exported int
$export_type Type of export used in filter names. string
$filename Filename to export to. string
$limit Batch limit. int
$exported_row_count Number exported. int
$row_data Raw data to export. array
$total_rows Total rows to export. int
$column_names Columns ids and names. array
$columns_to_export List of columns to export, or empty for all. array
$delimiter The delimiter parameter sets the field delimiter (one character only). string
__construct() Constructor. mixed
enable_meta_export() Should meta be exported? mixed
set_product_types_to_export() Product types to export. mixed
set_product_category_to_export() Product category to export void
get_default_column_names() Return an array of columns to export. array
prepare_data_to_export() Prepare data for export. mixed
generate_row_data() Take a product and generate row data from it for export. array
get_column_value_published() Get published value. int
get_column_value_sale_price() Get formatted sale price. string
get_column_value_regular_price() Get formatted regular price. string
get_column_value_category_ids() Get product_cat value. string
get_column_value_tag_ids() Get product_tag value. string
get_column_value_shipping_class_id() Get product_shipping_class value. string
get_column_value_images() Get images value. string
prepare_linked_products_for_export() Prepare linked products for export. string
get_column_value_cross_sell_ids() Get cross_sell_ids value. string
get_column_value_upsell_ids() Get upsell_ids value. string
get_column_value_parent_id() Get parent_id value. string
get_column_value_grouped_products() Get grouped_products value. string
get_column_value_download_limit() Get download_limit value. string
get_column_value_download_expiry() Get download_expiry value. string
get_column_value_stock() Get stock value. string
get_column_value_stock_status() Get stock status value. string
get_column_value_backorders() Get backorders. string
get_column_value_low_stock_amount() Get low stock amount value. int|string
get_column_value_type() Get type value. string
filter_description_field() Filter description field for export. string
prepare_downloads_for_export() Export downloads. mixed
prepare_attributes_for_export() Export attributes data. mixed
prepare_meta_for_export() Export meta data. mixed
__construct() Constructor. mixed
get_file_path() Get file path to export to. string
get_file() Get the file contents. string
export() Do the export. mixed
generate_file() Generate the CSV file. mixed
write_csv_data() Write data to the file. mixed
get_page() Get page. int
set_page() Set page. mixed
get_total_exported() Get count of records exported. int
get_percent_complete() Get total % complete. int
prepare_data_to_export() Prepare data that will be exported. mixed
get_column_names() Return an array of supported column names and ids. array
set_column_names() Set column names. mixed
get_columns_to_export() Return an array of columns to export. array
get_delimiter() Return the delimiter to use in CSV file string
set_columns_to_export() Set columns to export. mixed
is_column_exporting() See if a column is to be exported or not. bool
get_default_column_names() Return default columns. array
send_headers() Set the export headers. mixed
set_filename() Set filename to export to. mixed
get_filename() Generate and return a filename. string
send_content() Set the export content. mixed
get_csv_data() Get CSV data for this export. string
export_column_headers() Export column headers in CSV format. string
get_data_to_export() Get data that will be exported. array
export_rows() Export rows in CSV format. string
export_row() Export rows to an array ready for the CSV. mixed
get_limit() Get batch limit. int
set_limit() Set batch limit. mixed
escape_data() Escape a string to be used in a CSV context string
format_data() Format and escape data ready for the CSV file. string
format_term_ids() Format term ids to names. string
implode_values() Implode CSV cell values using commas by default, and wrapping values which contain the separator. string
fputcsv() Write to the CSV file, ensuring escaping works across versions of PHP. mixed

Properties

$product_category_to_export

Products belonging to what category should be exported.

protected string $product_category_to_export = array()

$columns_to_export

List of columns to export, or empty for all.

protected array $columns_to_export = array()

$delimiter

The delimiter parameter sets the field delimiter (one character only).

protected string $delimiter = ','

Methods

enable_meta_export()

Should meta be exported?

public enable_meta_export( $enable_meta_export : bool ) : mixed
Parameters
$enable_meta_export : bool

Should meta be exported.

Tags
since
Return values
mixed

set_product_types_to_export()

Product types to export.

public set_product_types_to_export( $product_types_to_export : array ) : mixed
Parameters
$product_types_to_export : array

List of types to export.

Tags
since
Return values
mixed

set_product_category_to_export()

Product category to export

public set_product_category_to_export( $product_category_to_export : string ) : void
Parameters
$product_category_to_export : string

Product category slug to export, empty string exports all.

Tags
since

get_default_column_names()

Return an array of columns to export.

public get_default_column_names( ) : array
Tags
since
Return values
array

get_column_value_shipping_class_id()

Get product_shipping_class value.

protected get_column_value_shipping_class_id( $product : WC_Product ) : string
Parameters
$product : WC_Product

Product being exported.

Tags
since
Return values
string

prepare_linked_products_for_export()

Prepare linked products for export.

protected prepare_linked_products_for_export( $linked_products : int[] ) : string
Parameters
$linked_products : int[]

Array of linked product ids.

Tags
since
Return values
string

get_column_value_cross_sell_ids()

Get cross_sell_ids value.

protected get_column_value_cross_sell_ids( $product : WC_Product ) : string
Parameters
$product : WC_Product

Product being exported.

Tags
since
Return values
string

get_column_value_grouped_products()

Get grouped_products value.

protected get_column_value_grouped_products( $product : WC_Product ) : string
Parameters
$product : WC_Product

Product being exported.

Tags
since
Return values
string

get_column_value_download_limit()

Get download_limit value.

protected get_column_value_download_limit( $product : WC_Product ) : string
Parameters
$product : WC_Product

Product being exported.

Tags
since
Return values
string

get_column_value_download_expiry()

Get download_expiry value.

protected get_column_value_download_expiry( $product : WC_Product ) : string
Parameters
$product : WC_Product

Product being exported.

Tags
since
Return values
string

get_column_value_low_stock_amount()

Get low stock amount value.

protected get_column_value_low_stock_amount( $product : WC_Product ) : int|string
Parameters
$product : WC_Product

Product being exported.

Tags
since
Return values
int|string

Empty string if value not set

filter_description_field()

Filter description field for export.

protected filter_description_field( $description : string ) : string

Convert newlines to '\n'.

Parameters
$description : string

Product description text to filter.

Tags
since
Return values
string

prepare_downloads_for_export()

Export downloads.

protected prepare_downloads_for_export( $product : WC_Product , &$row : array ) : mixed
Parameters
$product : WC_Product

Product being exported.

$row : array

Row being exported.

Tags
since
Return values
mixed

prepare_attributes_for_export()

Export attributes data.

protected prepare_attributes_for_export( $product : WC_Product , &$row : array ) : mixed
Parameters
$product : WC_Product

Product being exported.

$row : array

Row being exported.

Tags
since
Return values
mixed

prepare_meta_for_export()

Export meta data.

protected prepare_meta_for_export( $product : WC_Product , &$row : array ) : mixed
Parameters
$product : WC_Product

Product being exported.

$row : array

Row data.

Tags
since
Return values
mixed

write_csv_data()

Write data to the file.

protected write_csv_data( $data : string ) : mixed
Parameters
$data : string

Data.

Tags
since
Return values
mixed

get_total_exported()

Get count of records exported.

public get_total_exported( ) : int
Tags
since
Return values
int

prepare_data_to_export()

Prepare data that will be exported.

public abstract prepare_data_to_export( ) : mixed
Return values
mixed

get_column_names()

Return an array of supported column names and ids.

public get_column_names( ) : array
Tags
since
Return values
array

set_column_names()

Set column names.

public set_column_names( $column_names : array ) : mixed
Parameters
$column_names : array

Column names array.

Tags
since
Return values
mixed

get_columns_to_export()

Return an array of columns to export.

public get_columns_to_export( ) : array
Tags
since
Return values
array

get_delimiter()

Return the delimiter to use in CSV file

public get_delimiter( ) : string
Tags
since
Return values
string

set_columns_to_export()

Set columns to export.

public set_columns_to_export( $columns : array ) : mixed
Parameters
$columns : array

Columns array.

Tags
since
Return values
mixed

is_column_exporting()

See if a column is to be exported or not.

public is_column_exporting( $column_id : string ) : bool
Parameters
$column_id : string

ID of the column being exported.

Tags
since
Return values
bool

get_default_column_names()

Return default columns.

public get_default_column_names( ) : array
Tags
since
Return values
array

set_filename()

Set filename to export to.

public set_filename( $filename : string ) : mixed
Parameters
$filename : string

Filename to export to.

Return values
mixed

send_content()

Set the export content.

public send_content( $csv_data : string ) : mixed
Parameters
$csv_data : string

All CSV content.

Tags
since
Return values
mixed

get_csv_data()

Get CSV data for this export.

protected get_csv_data( ) : string
Tags
since
Return values
string

export_column_headers()

Export column headers in CSV format.

protected export_column_headers( ) : string
Tags
since
Return values
string

get_data_to_export()

Get data that will be exported.

protected get_data_to_export( ) : array
Tags
since
Return values
array

export_rows()

Export rows in CSV format.

protected export_rows( ) : string
Tags
since
Return values
string

export_row()

Export rows to an array ready for the CSV.

protected export_row( $row_data : array , $key : string , $buffer : resource ) : mixed
Parameters
$row_data : array

Data to export.

$key : string

Column being exported.

$buffer : resource

Output buffer.

Tags
since
Return values
mixed

set_limit()

Set batch limit.

public set_limit( $limit : int ) : mixed
Parameters
$limit : int

Limit to export.

Tags
since
Return values
mixed

escape_data()

Escape a string to be used in a CSV context

public escape_data( $data : string ) : 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
see
see
since
Return values
string

format_data()

Format and escape data ready for the CSV file.

public format_data( $data : string ) : string
Parameters
$data : string

Data to format.

Tags
since
Return values
string

format_term_ids()

Format term ids to names.

public format_term_ids( $term_ids : array , $taxonomy : string ) : string
Parameters
$term_ids : array

Term IDs to format.

$taxonomy : string

Taxonomy name.

Tags
since
Return values
string

implode_values()

Implode CSV cell values using commas by default, and wrapping values which contain the separator.

protected implode_values( $values : array ) : string
Parameters
$values : array

Values to implode.

Tags
since
Return values
string

fputcsv()

Write to the CSV file, ensuring escaping works across versions of PHP.

protected fputcsv( $buffer : resource , $export_row : array ) : mixed

PHP 5.5.4 uses '\' as the default escape character. This is not RFC-4180 compliant. \0 disables the escape character.

Parameters
$buffer : resource

Resource we are writing to.

$export_row : array

Row to export.

Tags
see
see
see
see
since
since
Return values
mixed
Back to the top