WooCommerce Code Reference

WC_Product_Importer
in package
implements WC_Importer_Interface

WC_Product_Importer Class.

Interfaces, Classes and Traits

WC_Importer_Interface
WC_Importer_Interface class.

Table of Contents

$file  : string
CSV file.
$file_position  : int
The file position after the last read.
$file_positions  : array<string|int, mixed>
Raw data.
$mapped_keys  : array<string|int, mixed>
Mapped keys - CSV headers.
$params  : array<string|int, mixed>
Importer parameters.
$parsed_data  : array<string|int, mixed>
Parsed data.
$raw_data  : array<string|int, mixed>
Raw data.
$raw_keys  : array<string|int, mixed>
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<string|int, mixed>
Get file mapped headers.
get_params()  : array<string|int, mixed>
Get importer parameters.
get_parsed_data()  : array<string|int, mixed>
Get parsed data.
get_percent_complete()  : int
Get file pointer position as a percentage of file size.
get_raw_data()  : array<string|int, mixed>
Get raw data.
get_raw_keys()  : array<string|int, mixed>
Get file raw headers.
explode_values()  : array<string|int, mixed>
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<string|int, mixed>
Get variation parent attributes and set "is_variation".
memory_exceeded()  : bool
Memory exceeded
process_item()  : array<string|int, mixed>|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<string|int, mixed>
Parameters
$value : string

Value to explode.

$separator : string = ','

Separator separating each value. Defaults to comma.

Tags
since
3.2.0
Return values
array<string|int, mixed>

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<string|int, mixed> $attributes, WC_Product $parent) : array<string|int, mixed>
Parameters
$attributes : array<string|int, mixed>

Attributes list.

$parent : WC_Product

Parent product data.

Return values
array<string|int, mixed>

process_item()

Process a single item and save.

protected process_item(array<string|int, mixed> $data) : array<string|int, mixed>|WP_Error
Parameters
$data : array<string|int, mixed>

Raw CSV data.

Tags
throws
Exception

If item cannot be processed.

Return values
array<string|int, mixed>|WP_Error

set_product_data()

Set product data.

protected set_product_data(WC_Product &$product, array<string|int, mixed> $data) : mixed
Parameters
$product : WC_Product

Product instance.

$data : array<string|int, mixed>

Item data.

Tags
throws
Exception

If data cannot be set.

Return values
mixed

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