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
$file
CSV file.
protected
string
$file
= ''
$file_position
The file position after the last read.
protected
int
$file_position
= 0
$file_positions
Raw data.
protected
array<string|int, mixed>
$file_positions
= array()
$mapped_keys
Mapped keys - CSV headers.
protected
array<string|int, mixed>
$mapped_keys
= array()
$params
Importer parameters.
protected
array<string|int, mixed>
$params
= array()
$parsed_data
Parsed data.
protected
array<string|int, mixed>
$parsed_data
= array()
$raw_data
Raw data.
protected
array<string|int, mixed>
$raw_data
= array()
$raw_keys
Raw keys - CSV raw headers.
protected
array<string|int, mixed>
$raw_keys
= array()
$start_time
Start time of current import.
protected
int
$start_time
= 0
(default value: 0)
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
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
Return values
int —get_file_position()
Get file pointer position from the last read.
public
get_file_position() : int
Return values
int —get_mapped_keys()
Get file mapped headers.
public
get_mapped_keys() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_params()
Get importer parameters.
public
get_params() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_parsed_data()
Get parsed data.
public
get_parsed_data() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_percent_complete()
Get file pointer position as a percentage of file size.
public
get_percent_complete() : int
Return values
int —get_raw_data()
Get raw data.
public
get_raw_data() : array<string|int, mixed>
Return values
array<string|int, mixed> —get_raw_keys()
Get file raw headers.
public
get_raw_keys() : array<string|int, mixed>
Return values
array<string|int, mixed> —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
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
Return values
string —get_memory_limit()
Get memory limit
protected
get_memory_limit() : int
Return values
int —get_product_object()
Prepare a single product for create or update.
protected
get_product_object(array<string|int, mixed> $data) : WC_Product|WP_Error
Parameters
- $data : array<string|int, mixed>
-
Item data.
Return values
WC_Product|WP_Error —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> —memory_exceeded()
Memory exceeded
protected
memory_exceeded() : bool
Ensures the batch process never exceeds 90% of the maximum WordPress memory.
Return values
bool —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
Return values
array<string|int, mixed>|WP_Error —set_image_data()
Convert raw image URLs to IDs and set.
protected
set_image_data(WC_Product &$product, array<string|int, mixed> $data) : mixed
Parameters
- $product : WC_Product
-
Product instance.
- $data : array<string|int, mixed>
-
Item data.
Return values
mixed —set_meta_data()
Append meta data.
protected
set_meta_data(WC_Product &$product, array<string|int, mixed> $data) : mixed
Parameters
- $product : WC_Product
-
Product instance.
- $data : array<string|int, mixed>
-
Item data.
Return values
mixed —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
Return values
mixed —set_variation_data()
Set variation data.
protected
set_variation_data(WC_Product &$variation, array<string|int, mixed> $data) : WC_Product|WP_Error
Parameters
- $variation : WC_Product
-
Product instance.
- $data : array<string|int, mixed>
-
Item data.
Tags
Return values
WC_Product|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 '.