WooCommerce Code Reference

WC_Product_Importer
in package
implements WC_Importer_Interface

WC_Product_Importer Class.

Interfaces, Classes and Traits

WC_Importer_Interface
WooCommerce Importer Interface

Table of Contents

$file  : string
CSV file.
$file_position  : int
The file position after the last read.
$file_positions  : array
Raw data.
$mapped_keys  : array
Mapped keys - CSV headers.
$params  : array
Importer parameters.
$parsed_data  : array
Parsed data.
$raw_data  : array
Raw data.
$raw_keys  : array
Raw keys - CSV raw headers.
$start_time  : int
Start time of current import.
get_attachment_id_from_url()  : int
Get attachment ID.
get_attribute_taxonomy_id()  : int
Get attribute taxonomy ID from the imported data.
get_file_position()  : int
Get file pointer position from the last read.
get_mapped_keys()  : array
Get file mapped headers.
get_params()  : array
Get importer parameters.
get_parsed_data()  : array
Get parsed data.
get_percent_complete()  : int
Get file pointer position as a percentage of file size.
get_raw_data()  : array
Get raw data.
get_raw_keys()  : array
Get file raw headers.
explode_values()  : array
Explode CSV cell values using commas by default, and handling escaped separators.
explode_values_formatter()  : string
Remove formatting and trim each value.
get_memory_limit()  : int
Get memory limit
get_product_object()  : WC_Product|WP_Error
Prepare a single product for create or update.
get_variation_parent_attributes()  : array
Get variation parent attributes and set "is_variation".
memory_exceeded()  : bool
Memory exceeded
process_item()  : array|WP_Error
Process a single item and save.
set_image_data()  : mixed
Convert raw image URLs to IDs and set.
set_meta_data()  : mixed
Append meta data.
set_product_data()  : mixed
Set product data.
set_variation_data()  : WC_Product|WP_Error
Set variation data.
time_exceeded()  : bool
Time exceeded.
unescape_data()  : string
The exporter prepends a ' to escape fields that start with =, +, - or @.

Properties

Methods

get_attachment_id_from_url()

Get attachment ID.

public get_attachment_id_from_url(string $url, int $product_id) : int
Parameters
$url : string

Attachment URL.

$product_id : int

Product ID.

Tags
throws
Exception

If attachment cannot be loaded.

Return values
int

get_attribute_taxonomy_id()

Get attribute taxonomy ID from the imported data.

public get_attribute_taxonomy_id(string $raw_name) : int

If does not exists register a new attribute.

Parameters
$raw_name : string

Attribute name.

Tags
throws
Exception

If taxonomy cannot be loaded.

Return values
int

explode_values()

Explode CSV cell values using commas by default, and handling escaped separators.

protected explode_values(string $value[, string $separator = ',' ]) : array
Parameters
$value : string

Value to explode.

$separator : string = ','

Separator separating each value. Defaults to comma.

Tags
since
3.2.0
Return values
array

explode_values_formatter()

Remove formatting and trim each value.

protected explode_values_formatter(string $value) : string
Parameters
$value : string

Value to format.

Tags
since
3.2.0
Return values
string

get_variation_parent_attributes()

Get variation parent attributes and set "is_variation".

protected get_variation_parent_attributes(array $attributes, WC_Product $parent) : array
Parameters
$attributes : array

Attributes list.

$parent : WC_Product

Parent product data.

Return values
array

process_item()

Process a single item and save.

protected process_item(array $data) : array|WP_Error
Parameters
$data : array

Raw CSV data.

Tags
throws
Exception

If item cannot be processed.

Return values
array|WP_Error

time_exceeded()

Time exceeded.

protected time_exceeded() : bool

Ensures the batch never exceeds a sensible time limit. A timeout limit of 30s is common on shared hosting.

Return values
bool

unescape_data()

The exporter prepends a ' to escape fields that start with =, +, - or @.

protected unescape_data(string $value) : string

Remove the prepended ' character preceding those characters.

Parameters
$value : string

A string that may or may not have been escaped with '.

Tags
since
3.5.2
Return values
string