WooCommerce Code Reference

WC_Customer_Download_Data_Store
in package
implements WC_Customer_Download_Data_Store_Interface

WC Customer Download Data Store.

Tags
version
3.0.0

Interfaces, Classes and Traits

WC_Customer_Download_Data_Store_Interface
WC Customer Download Data Store Interface.

Table of Contents

DOWNLOAD_PERMISSION_DB_FIELDS  = array('download_id', 'product_id', 'user_id', 'user_email', 'order_id', 'order_key', 'downloads_remaining', 'access_granted', 'download_count', 'access_expires')
Names of the database fields for the download permissions table.
create()  : mixed
Create download permission for a user.
create_from_data()  : mixed
Create download permission for a user, from an array of data.
delete()  : mixed
Method to delete a download permission from the database.
delete_by_download_id()  : mixed
Method to delete a download permission from the database by download ID.
delete_by_id()  : mixed
Method to delete a download permission from the database by ID.
delete_by_order_id()  : mixed
Method to delete a download permission from the database by order ID.
delete_by_user_email()  : bool
Method to delete a download permission from the database by user email.
delete_by_user_id()  : bool
Method to delete a download permission from the database by user ID.
get_downloads()  : array<string|int, mixed>
Get array of download ids by specified args.
get_downloads_for_customer()  : array<string|int, mixed>
Get a customers downloads.
read()  : mixed
Method to read a download permission from the database.
update()  : mixed
Method to update a download in the database.
update_download_id()  : mixed
Update download ids if the hash changes.
update_user_by_order_id()  : mixed
Update user prop for downloads based on order id.
adjust_date_for_db()  : string
Adjust a date value to be inserted in the database.
get_download()  : WC_Customer_Download
Get a download object.
insert_new_download_permission()  : int
Create download permission for a user, from an array of data.

Constants

DOWNLOAD_PERMISSION_DB_FIELDS

Names of the database fields for the download permissions table.

public mixed DOWNLOAD_PERMISSION_DB_FIELDS = array('download_id', 'product_id', 'user_id', 'user_email', 'order_id', 'order_key', 'downloads_remaining', 'access_granted', 'download_count', 'access_expires')

Methods

create_from_data()

Create download permission for a user, from an array of data.

public create_from_data(array<string|int, mixed> $data) : mixed
Parameters
$data : array<string|int, mixed>

Data to create the permission for.

Tags
returns

int The database id of the created permission, or false if the permission creation failed.

Return values
mixed

delete_by_download_id()

Method to delete a download permission from the database by download ID.

public delete_by_download_id(int $id) : mixed
Parameters
$id : int

download_id of the downloads that will be deleted.

Return values
mixed

delete_by_user_email()

Method to delete a download permission from the database by user email.

public delete_by_user_email(string $email) : bool
Parameters
$email : string

email of the downloads that will be deleted.

Tags
since
3.4.0
Return values
boolTrue if deleted rows.

delete_by_user_id()

Method to delete a download permission from the database by user ID.

public delete_by_user_id(int $id) : bool
Parameters
$id : int

user ID of the downloads that will be deleted.

Tags
since
3.4.0
Return values
boolTrue if deleted rows.

get_downloads()

Get array of download ids by specified args.

public get_downloads([array<string|int, mixed> $args = array() ]) : array<string|int, mixed>
Parameters
$args : array<string|int, mixed> = array()

Arguments to filter downloads. $args['return'] accepts the following values: 'objects' (default), 'ids' or a comma separeted list of fields (for example: 'order_id,user_id,user_email').

Return values
array<string|int, mixed>Can be an array of permission_ids, an array of WC_Customer_Download objects or an array of arrays containing specified fields depending on the value of $args['return'].

update_download_id()

Update download ids if the hash changes.

public update_download_id(int $product_id, string $old_id, string $new_id) : mixed
Parameters
$product_id : int

Product ID.

$old_id : string

Old download_id.

$new_id : string

New download_id.

Tags
deprecated
3.3.0

Download id is now a static UUID and should not be changed based on file hash.

Return values
mixed

update_user_by_order_id()

Update user prop for downloads based on order id.

public update_user_by_order_id(int $order_id, int $customer_id, string $email) : mixed
Parameters
$order_id : int

Order ID.

$customer_id : int

Customer ID.

$email : string

Customer email address.

Return values
mixed

adjust_date_for_db()

Adjust a date value to be inserted in the database.

private adjust_date_for_db(mixed $date) : string
Parameters
$date : mixed

The date value. Can be a WC_DateTime, a timestamp, or anything else that "date" recognizes.

Tags
throws
Exception

The passed value can't be converted to a date.

Return values
stringThe date converted to 'Y-m-d' format.

insert_new_download_permission()

Create download permission for a user, from an array of data.

private insert_new_download_permission(array<string|int, mixed> $data) : int

Assumes that all the keys in the passed data are valid.

Parameters
$data : array<string|int, mixed>

Data to create the permission for.

Return values
intThe database id of the created permission, or false if the permission creation failed.