PHP Class WC_Product_Data_Store_CPT

Author: WooThemes
Inheritance: extends WC_Data_Store_WP, implements WC_Object_Data_Store_Interface, implements WC_Product_Data_Store_Interface
ファイルを表示 Open project: woocommerce/woocommerce Class Usage Examples

Protected Properties

Property Type Description
$extra_data_saved If we have already saved our extra data, don't do automatic / default handling.
$internal_meta_keys array Data stored in meta keys, but not considered "meta".

Public Methods

Method Description
create ( &$product ) Method to create a new product in the database.
delete ( &$product, array $args = [] ) Method to delete a product from the database.
find_matching_product_variation ( WC_Product $product, array $match_attributes = [] ) : integer Find a matching (enabled) variation within a variable product.
get_ending_sales ( ) : array Returns an array of IDs of products that have sales which are due to end.
get_featured_product_ids ( ) : array Returns a list of product IDs ( id as key => parent as value) that are featured. Uses get_posts instead of wc_get_products since we want some extra meta queries and ALL products (posts_per_page = -1).
get_on_sale_products ( ) : array Returns an array of on sale products, as an array of objects with an ID and parent_id present. Example: $return[0]->id, $return[0]->parent_id.
get_product_id_by_sku ( string $sku ) : integer Return product ID based on SKU.
get_products ( array $args = [] ) : array Returns an array of products.
get_related_products ( array $cats_array, array $tags_array, array $exclude_ids, integer $limit, integer $product_id ) : array Return a list of related products (using data like categories and IDs).
get_related_products_query ( array $cats_array, array $tags_array, array $exclude_ids, integer $limit ) : string Builds the related posts query.
get_shipping_class_id_by_slug ( $slug ) : integer | false Get shipping class ID by slug.
get_starting_sales ( ) : array Returns an array of IDs of products that have sales starting soon.
is_existing_sku ( integer $product_id, string $sku ) : boolean Check if product sku is found for any other product IDs.
read ( &$product ) Method to read a product from the database.
search_products ( string $term, string $type = '', boolean $include_variations = false ) : array Search product data for a term and return ids.
update ( &$product ) Method to update a product in the database.
update_average_rating ( WC_Product $product ) Update a products average rating meta.
update_product_stock ( $product_id_with_stock, integer | null $stock_quantity = null, string $operation = 'set' ) Update a product's stock amount directly.
update_rating_counts ( WC_Product $product ) Update a products rating counts.
update_review_count ( WC_Product $product ) Update a products review count meta.

Protected Methods

Method Description
clear_caches ( &$product ) Clear any caches.
read_attributes ( &$product ) Read attributes from post meta.
read_downloads ( &$product ) Read downloads from post meta.
read_product_data ( &$product ) Read product data. Can be overridden by child classes to load other props.
update_attributes ( &$product ) Update attributes which are a mix of terms and meta data.
update_downloads ( &$product ) Update downloads.
update_post_meta ( &$product ) Helper method that updates all the post meta for a product based on it's settings in the WC_Product class.
update_term_counts ( &$product ) Count terms. These are done at this point so all product props are set in advance.
update_terms ( &$product ) For all stored terms in all taxonomies, save them to the DB.
update_version_and_type ( &$product ) Make sure we store the product type and version (to track data changes).

Method Details

clear_caches() protected method

Clear any caches.
Since: 2.7.0
protected clear_caches ( &$product )

create() public method

Method to create a new product in the database.
public create ( &$product )

delete() public method

Method to delete a product from the database.
public delete ( &$product, array $args = [] )
$args array Array of args to pass to the delete method.

find_matching_product_variation() public method

Find a matching (enabled) variation within a variable product.
Since: 2.7.0
public find_matching_product_variation ( WC_Product $product, array $match_attributes = [] ) : integer
$product WC_Product Variable product.
$match_attributes array Array of attributes we want to try to match.
return integer Matching variation ID or 0.

get_ending_sales() public method

Returns an array of IDs of products that have sales which are due to end.
Since: 2.7.0
public get_ending_sales ( ) : array
return array

get_on_sale_products() public method

Returns an array of on sale products, as an array of objects with an ID and parent_id present. Example: $return[0]->id, $return[0]->parent_id.
Since: 2.7.0
public get_on_sale_products ( ) : array
return array

get_product_id_by_sku() public method

Return product ID based on SKU.
Since: 2.7.0
public get_product_id_by_sku ( string $sku ) : integer
$sku string
return integer

get_products() public method

Returns an array of products.
public get_products ( array $args = [] ) : array
$args array @see wc_get_products
return array

get_shipping_class_id_by_slug() public method

Get shipping class ID by slug.
Since: 2.7.0
public get_shipping_class_id_by_slug ( $slug ) : integer | false
$slug string
return integer | false

get_starting_sales() public method

Returns an array of IDs of products that have sales starting soon.
Since: 2.7.0
public get_starting_sales ( ) : array
return array

is_existing_sku() public method

Check if product sku is found for any other product IDs.
Since: 2.7.0
public is_existing_sku ( integer $product_id, string $sku ) : boolean
$product_id integer
$sku string Will be slashed to work around https://core.trac.wordpress.org/ticket/27421
return boolean

read() public method

Method to read a product from the database.
public read ( &$product )

read_attributes() protected method

Read attributes from post meta.
Since: 2.7.0
protected read_attributes ( &$product )

read_downloads() protected method

Read downloads from post meta.
Since: 2.7.0
protected read_downloads ( &$product )

read_product_data() protected method

Read product data. Can be overridden by child classes to load other props.
Since: 2.7.0
protected read_product_data ( &$product )

search_products() public method

Search product data for a term and return ids.
public search_products ( string $term, string $type = '', boolean $include_variations = false ) : array
$term string
$type string of product
$include_variations boolean in search or not
return array of ids

update() public method

Method to update a product in the database.
public update ( &$product )

update_attributes() protected method

Update attributes which are a mix of terms and meta data.
Since: 2.7.0
protected update_attributes ( &$product )

update_average_rating() public method

Update a products average rating meta.
Since: 2.7.0
public update_average_rating ( WC_Product $product )
$product WC_Product

update_downloads() protected method

Update downloads.
Since: 2.7.0
protected update_downloads ( &$product )

update_post_meta() protected method

Helper method that updates all the post meta for a product based on it's settings in the WC_Product class.
Since: 2.7.0
protected update_post_meta ( &$product )

update_product_stock() public method

Uses queries rather than update_post_meta so we can do this in one query (to avoid stock issues).
Since: 2.7.0 this supports set, increase and decrease.
public update_product_stock ( $product_id_with_stock, integer | null $stock_quantity = null, string $operation = 'set' )
$stock_quantity integer | null
$operation string set, increase and decrease.

update_rating_counts() public method

Update a products rating counts.
Since: 2.7.0
public update_rating_counts ( WC_Product $product )
$product WC_Product

update_review_count() public method

Update a products review count meta.
Since: 2.7.0
public update_review_count ( WC_Product $product )
$product WC_Product

update_term_counts() protected method

Count terms. These are done at this point so all product props are set in advance.
Since: 2.7.0
protected update_term_counts ( &$product )

update_terms() protected method

For all stored terms in all taxonomies, save them to the DB.
Since: 2.7.0
protected update_terms ( &$product )

update_version_and_type() protected method

Make sure we store the product type and version (to track data changes).
Since: 2.7.0
protected update_version_and_type ( &$product )

Property Details

$extra_data_saved protected_oe property

If we have already saved our extra data, don't do automatic / default handling.
protected $extra_data_saved

$internal_meta_keys protected_oe property

Data stored in meta keys, but not considered "meta".
Since: 2.7.0
protected array $internal_meta_keys
return array