PHP Class WC_Product

The WooCommerce product class handles individual product data.
Author: WooThemes
Afficher le fichier Open project: woocommerce/woocommerce Class Usage Examples

Protected Properties

Свойство Type Description
$cache_group string Cache group.
$data array Stores product data.
$post_type string Post type.
$supports array Supported features such as 'ajax_add_to_cart'.

Méthodes publiques

Méthode Description
__construct ( integer | WC_Product | object $product ) Get the product if ID is passed, otherwise the product is new and empty.
add_to_cart_text ( ) : string Get the add to cart button text.
add_to_cart_url ( ) : string Get the add to url used mainly in loops.
backorders_allowed ( ) : boolean Returns whether or not the product can be backordered.
backorders_require_notification ( ) : boolean Returns whether or not the product needs to notify the customer on backorder.
child_has_dimensions ( ) : boolean Does a child have dimensions?
child_has_weight ( ) : boolean Does a child have a weight?
exists ( ) : boolean Returns whether or not the product post exists.
get_attribute ( string $attribute ) : string Returns a single product attribute as a string.
get_attributes ( string $context = 'view' ) : array Returns product attributes.
get_average_rating ( string $context = 'view' ) : float Get average rating.
get_backorders ( string $context = 'view' ) : string Get backorders.
get_catalog_visibility ( string $context = 'view' ) : string Get catalog visibility.
get_category_ids ( string $context = 'view' ) : array Get category ids.
get_children ( ) : array Returns the children IDs if applicable. Overridden by child classes.
get_cross_sell_ids ( string $context = 'view' ) : array Get cross sell IDs.
get_data ( ) : array Get all class data in array format.
get_date_created ( string $context = 'view' ) : string Get product created date.
get_date_modified ( string $context = 'view' ) : string Get product modified date.
get_date_on_sale_from ( string $context = 'view' ) : string Get date on sale from.
get_date_on_sale_to ( string $context = 'view' ) : string Get date on sale to.
get_default_attributes ( string $context = 'view' ) : array Get default attributes.
get_description ( string $context = 'view' ) : string Get product description.
get_dimensions ( $formatted = true ) : string | array Returns formatted dimensions.
get_download_expiry ( string $context = 'view' ) : integer Get download expiry.
get_download_limit ( string $context = 'view' ) : integer Get download limit.
get_downloadable ( string $context = 'view' ) : boolean Get downloadable.
get_downloads ( string $context = 'view' ) : array Get downloads.
get_featured ( string $context = 'view' ) : boolean If the product is featured.
get_file ( string $download_id = '' ) : array | false Get a file by $download_id.
get_file_download_path ( string $download_id ) : string Get file download path identified by $download_id.
get_formatted_name ( ) : string Get product name with SKU or ID. Used within admin.
get_gallery_image_ids ( string $context = 'view' ) : array Returns the gallery attachment ids.
get_height ( string $context = 'view' ) : string Returns the product height.
get_image ( string $size = 'shop_thumbnail', array $attr = [], $placeholder = true ) : string Returns the main product image.
get_image_id ( string $context = 'view' ) : string Get main image ID.
get_length ( string $context = 'view' ) : string Returns the product length.
get_manage_stock ( string $context = 'view' ) : boolean Return if product manage stock.
get_menu_order ( string $context = 'view' ) : integer Get menu order.
get_name ( string $context = 'view' ) : string Get product name.
get_parent_id ( string $context = 'view' ) : integer Get parent ID.
get_permalink ( ) : string Product permalink.
get_price ( string $context = 'view' ) : string Returns the product's active price.
get_price_html ( $deprecated = '' ) : string Returns the price in html format.
get_purchase_note ( string $context = 'view' ) : string Get purchase note.
get_rating_count ( integer $value = null ) : integer Get the total amount (COUNT) of ratings, or just the count for one rating e.g. number of 5 star ratings.
get_rating_counts ( string $context = 'view' ) : array Get rating count.
get_regular_price ( string $context = 'view' ) : string Returns the product's regular price.
get_review_count ( string $context = 'view' ) : integer Get review count.
get_reviews_allowed ( string $context = 'view' ) : boolean Return if reviews is allowed.
get_sale_price ( string $context = 'view' ) : string Returns the product's sale price.
get_shipping_class ( ) : string Returns the product shipping class SLUG.
get_shipping_class_id ( string $context = 'view' ) : integer Get shipping class ID.
get_short_description ( string $context = 'view' ) : string Get product short description.
get_sku ( string $context = 'view' ) : string Get SKU (Stock-keeping unit) - product unique ID.
get_slug ( string $context = 'view' ) : string Get product slug.
get_sold_individually ( string $context = 'view' ) : boolean Return if should be sold individually.
get_status ( string $context = 'view' ) : string Get product status.
get_stock_managed_by_id ( ) : integer If the stock level comes from another product ID, this should be modified.
get_stock_quantity ( string $context = 'view' ) : integer | null Returns number of items available for sale.
get_stock_status ( string $context = 'view' ) : string Return the stock status.
get_tag_ids ( string $context = 'view' ) : array Get tag ids.
get_tax_class ( string $context = 'view' ) : string Returns the tax class.
get_tax_status ( string $context = 'view' ) : string Returns the tax status.
get_title ( ) : string Get the product's title. For products this is the product name.
get_total_sales ( string $context = 'view' ) : integer Get number total of sales.
get_type ( ) : string Get internal type. Should return string and *should be overridden* by child classes.
get_upsell_ids ( string $context = 'view' ) : array Get upsel IDs.
get_virtual ( string $context = 'view' ) : boolean Get virtual.
get_weight ( string $context = 'view' ) : string Returns the product's weight.
get_width ( string $context = 'view' ) : string Returns the product width.
has_attributes ( ) : boolean Returns whether or not the product has any visible attributes.
has_child ( ) : boolean Returns whether or not the product has any child product.
has_dimensions ( ) : boolean Returns whether or not the product has dimensions set.
has_enough_stock ( mixed $quantity ) : boolean Returns whether or not the product has enough stock for the order.
has_file ( string $download_id = '' ) : boolean Check if downloadable product has a file attached.
has_weight ( ) : boolean Returns whether or not the product has weight set.
is_downloadable ( ) : boolean Checks if a product is downloadable.
is_featured ( ) : boolean Returns whether or not the product is featured.
is_in_stock ( ) : boolean Returns whether or not the product is in stock.
is_on_backorder ( integer $qty_in_cart ) : boolean Check if a product is on backorder.
is_on_sale ( ) : boolean Returns whether or not the product is on sale.
is_purchasable ( ) : boolean Returns false if the product cannot be bought.
is_shipping_taxable ( ) : boolean Returns whether or not the product shipping is taxable.
is_sold_individually ( ) : boolean Check if a product is sold individually (no quantities).
is_taxable ( ) : boolean Returns whether or not the product is taxable.
is_type ( string $type ) : boolean Checks the product type.
is_virtual ( ) : boolean Checks if a product is virtual (has no shipping).
is_visible ( ) : boolean Returns whether or not the product is visible in the catalog.
managing_stock ( ) : boolean Returns whether or not the product is stock managed.
needs_shipping ( ) : boolean Checks if a product needs shipping.
save ( ) Save data (either create or update depending on if we are working on an existing product).
set_attributes ( array $raw_attributes ) Set product attributes.
set_average_rating ( float $average ) Set average rating. Read only.
set_backorders ( string $backorders ) Set backorders.
set_catalog_visibility ( string $visibility ) Set catalog visibility.
set_category_ids ( array $term_ids ) Set the product categories.
set_cross_sell_ids ( array $cross_sell_ids ) Set crosssell IDs.
set_date_created ( string $timestamp ) Set product created date.
set_date_modified ( string $timestamp ) Set product modified date.
set_date_on_sale_from ( string $timestamp ) Set date on sale from.
set_date_on_sale_to ( string $timestamp ) Set date on sale to.
set_default_attributes ( array $default_attributes ) Set default attributes.
set_description ( string $description ) Set product description.
set_download_expiry ( integer $download_expiry ) Set download expiry.
set_download_limit ( integer $download_limit ) Set download limit.
set_downloadable ( $downloadable ) Set if the product is downloadable.
set_downloads ( $downloads_array ) Set downloads.
set_featured ( $featured ) Set if the product is featured.
set_gallery_image_ids ( array $image_ids ) Set gallery attachment ids.
set_height ( float | string $height ) Set the product height.
set_image_id ( integer $image_id = '' ) Set main image ID.
set_length ( float | string $length ) Set the product length.
set_manage_stock ( $manage_stock ) Set if product manage stock.
set_menu_order ( integer $menu_order ) Set menu order.
set_name ( string $name ) Set product name.
set_parent_id ( integer $parent_id ) Set parent ID.
set_price ( string $price ) Set the product's active price.
set_purchase_note ( string $purchase_note ) Set purchase note.
set_rating_counts ( array $counts ) Set rating counts. Read only.
set_regular_price ( string $price ) Set the product's regular price.
set_review_count ( integer $count ) Set review count. Read only.
set_reviews_allowed ( boolean $reviews_allowed ) Set if reviews is allowed.
set_sale_price ( string $price ) Set the product's sale price.
set_shipping_class_id ( $id ) Set shipping class ID.
set_short_description ( string $short_description ) Set product short description.
set_sku ( string $sku ) Set SKU.
set_slug ( string $slug ) Set product slug.
set_sold_individually ( $sold_individually ) Set if should be sold individually.
set_status ( string $status ) Set product status.
set_stock_quantity ( float | null $quantity ) Set number of items available for sale.
set_stock_status ( string $status = '' ) Set stock status.
set_tag_ids ( array $term_ids ) Set the product tags.
set_tax_class ( string $class ) Set the tax class.
set_tax_status ( string $status ) Set the tax status.
set_total_sales ( integer $total ) Set number total of sales.
set_upsell_ids ( array $upsell_ids ) Set upsell IDs.
set_virtual ( $virtual ) Set if the product is virtual.
set_weight ( float | string $weight ) Set the product's weight.
set_width ( float | string $width ) Set the product width.
single_add_to_cart_text ( ) : string Get the add to cart button text for the single page.
supports ( string $feature ) : boolean Check if a product supports a given feature.
validate_props ( ) Ensure properties are set correctly before save.

Méthodes protégées

Méthode Description
get_hook_prefix ( ) : string Prefix for action and filter hooks on data.
sanitize_term_ids ( array $terms, string $taxonomy ) Get term ids from either a list of names, ids, or terms.

Method Details

__construct() public méthode

This class should NOT be instantiated, but the wc_get_product() function should be used. It is possible, but the wc_get_product() is preferred.
public __construct ( integer | WC_Product | object $product )
$product integer | WC_Product | object Product to init.

add_to_cart_text() public méthode

Get the add to cart button text.
public add_to_cart_text ( ) : string
Résultat string

add_to_cart_url() public méthode

Get the add to url used mainly in loops.
public add_to_cart_url ( ) : string
Résultat string

backorders_allowed() public méthode

Returns whether or not the product can be backordered.
public backorders_allowed ( ) : boolean
Résultat boolean

backorders_require_notification() public méthode

Returns whether or not the product needs to notify the customer on backorder.

child_has_dimensions() public méthode

Does a child have dimensions?
Since: 2.7.0
public child_has_dimensions ( ) : boolean
Résultat boolean

child_has_weight() public méthode

Does a child have a weight?
Since: 2.7.0
public child_has_weight ( ) : boolean
Résultat boolean

exists() public méthode

Returns whether or not the product post exists.
public exists ( ) : boolean
Résultat boolean

get_attribute() public méthode

Returns a single product attribute as a string.
public get_attribute ( string $attribute ) : string
$attribute string to get.
Résultat string

get_attributes() public méthode

Returns product attributes.
public get_attributes ( string $context = 'view' ) : array
$context string
Résultat array

get_average_rating() public méthode

Get average rating.
public get_average_rating ( string $context = 'view' ) : float
$context string
Résultat float

get_backorders() public méthode

Get backorders.
Since: 2.7.0
public get_backorders ( string $context = 'view' ) : string
$context string
Résultat string yes no or notify

get_catalog_visibility() public méthode

Get catalog visibility.
Since: 2.7.0
public get_catalog_visibility ( string $context = 'view' ) : string
$context string
Résultat string

get_category_ids() public méthode

Get category ids.
Since: 2.7.0
public get_category_ids ( string $context = 'view' ) : array
$context string
Résultat array

get_children() public méthode

Returns the children IDs if applicable. Overridden by child classes.
public get_children ( ) : array
Résultat array of IDs

get_cross_sell_ids() public méthode

Get cross sell IDs.
Since: 2.7.0
public get_cross_sell_ids ( string $context = 'view' ) : array
$context string
Résultat array

get_data() public méthode

Get all class data in array format.
Since: 2.7.0
public get_data ( ) : array
Résultat array

get_date_created() public méthode

Get product created date.
Since: 2.7.0
public get_date_created ( string $context = 'view' ) : string
$context string
Résultat string Timestamp.

get_date_modified() public méthode

Get product modified date.
Since: 2.7.0
public get_date_modified ( string $context = 'view' ) : string
$context string
Résultat string Timestamp.

get_date_on_sale_from() public méthode

Get date on sale from.
Since: 2.7.0
public get_date_on_sale_from ( string $context = 'view' ) : string
$context string
Résultat string

get_date_on_sale_to() public méthode

Get date on sale to.
Since: 2.7.0
public get_date_on_sale_to ( string $context = 'view' ) : string
$context string
Résultat string

get_default_attributes() public méthode

Get default attributes.
Since: 2.7.0
public get_default_attributes ( string $context = 'view' ) : array
$context string
Résultat array

get_description() public méthode

Get product description.
Since: 2.7.0
public get_description ( string $context = 'view' ) : string
$context string
Résultat string

get_dimensions() public méthode

Returns formatted dimensions.
public get_dimensions ( $formatted = true ) : string | array
$formatted True by default for legacy support - will be false/not set in future versions to return the array only. Use wc_format_dimensions for formatted versions instead.
Résultat string | array

get_download_expiry() public méthode

Get download expiry.
Since: 2.7.0
public get_download_expiry ( string $context = 'view' ) : integer
$context string
Résultat integer

get_download_limit() public méthode

Get download limit.
Since: 2.7.0
public get_download_limit ( string $context = 'view' ) : integer
$context string
Résultat integer

get_downloadable() public méthode

Get downloadable.
Since: 2.7.0
public get_downloadable ( string $context = 'view' ) : boolean
$context string
Résultat boolean

get_downloads() public méthode

Get downloads.
Since: 2.7.0
public get_downloads ( string $context = 'view' ) : array
$context string
Résultat array

get_file() public méthode

Get a file by $download_id.
public get_file ( string $download_id = '' ) : array | false
$download_id string file identifier
Résultat array | false if not found

get_file_download_path() public méthode

Get file download path identified by $download_id.
public get_file_download_path ( string $download_id ) : string
$download_id string file identifier
Résultat string

get_formatted_name() public méthode

Get product name with SKU or ID. Used within admin.
public get_formatted_name ( ) : string
Résultat string Formatted product name

get_height() public méthode

Returns the product height.
public get_height ( string $context = 'view' ) : string
$context string
Résultat string

get_hook_prefix() protected méthode

Prefix for action and filter hooks on data.
Since: 2.7.0
protected get_hook_prefix ( ) : string
Résultat string

get_image() public méthode

Returns the main product image.
public get_image ( string $size = 'shop_thumbnail', array $attr = [], $placeholder = true ) : string
$size string (default: 'shop_thumbnail')
$attr array
Résultat string

get_image_id() public méthode

Get main image ID.
Since: 2.7.0
public get_image_id ( string $context = 'view' ) : string
$context string
Résultat string

get_length() public méthode

Returns the product length.
public get_length ( string $context = 'view' ) : string
$context string
Résultat string

get_manage_stock() public méthode

Return if product manage stock.
Since: 2.7.0
public get_manage_stock ( string $context = 'view' ) : boolean
$context string
Résultat boolean

get_menu_order() public méthode

Get menu order.
Since: 2.7.0
public get_menu_order ( string $context = 'view' ) : integer
$context string
Résultat integer

get_name() public méthode

Get product name.
Since: 2.7.0
public get_name ( string $context = 'view' ) : string
$context string
Résultat string

get_parent_id() public méthode

Get parent ID.
Since: 2.7.0
public get_parent_id ( string $context = 'view' ) : integer
$context string
Résultat integer

get_price() public méthode

Returns the product's active price.
public get_price ( string $context = 'view' ) : string
$context string
Résultat string price

get_price_html() public méthode

Returns the price in html format.
public get_price_html ( $deprecated = '' ) : string
Résultat string

get_purchase_note() public méthode

Get purchase note.
Since: 2.7.0
public get_purchase_note ( string $context = 'view' ) : string
$context string
Résultat string

get_rating_count() public méthode

Get the total amount (COUNT) of ratings, or just the count for one rating e.g. number of 5 star ratings.
public get_rating_count ( integer $value = null ) : integer
$value integer Optional. Rating value to get the count for. By default returns the count of all rating values.
Résultat integer

get_rating_counts() public méthode

Get rating count.
public get_rating_counts ( string $context = 'view' ) : array
$context string
Résultat array of counts

get_regular_price() public méthode

Returns the product's regular price.
public get_regular_price ( string $context = 'view' ) : string
$context string
Résultat string price

get_review_count() public méthode

Get review count.
public get_review_count ( string $context = 'view' ) : integer
$context string
Résultat integer

get_reviews_allowed() public méthode

Return if reviews is allowed.
Since: 2.7.0
public get_reviews_allowed ( string $context = 'view' ) : boolean
$context string
Résultat boolean

get_sale_price() public méthode

Returns the product's sale price.
public get_sale_price ( string $context = 'view' ) : string
$context string
Résultat string price

get_shipping_class() public méthode

Returns the product shipping class SLUG.
public get_shipping_class ( ) : string
Résultat string

get_shipping_class_id() public méthode

Get shipping class ID.
Since: 2.7.0
public get_shipping_class_id ( string $context = 'view' ) : integer
$context string
Résultat integer

get_short_description() public méthode

Get product short description.
Since: 2.7.0
public get_short_description ( string $context = 'view' ) : string
$context string
Résultat string

get_sku() public méthode

Get SKU (Stock-keeping unit) - product unique ID.
public get_sku ( string $context = 'view' ) : string
$context string
Résultat string

get_slug() public méthode

Get product slug.
Since: 2.7.0
public get_slug ( string $context = 'view' ) : string
$context string
Résultat string

get_sold_individually() public méthode

Return if should be sold individually.
Since: 2.7.0
public get_sold_individually ( string $context = 'view' ) : boolean
$context string
Résultat boolean

get_status() public méthode

Get product status.
Since: 2.7.0
public get_status ( string $context = 'view' ) : string
$context string
Résultat string

get_stock_managed_by_id() public méthode

If the stock level comes from another product ID, this should be modified.
Since: 2.7.0
public get_stock_managed_by_id ( ) : integer
Résultat integer

get_stock_quantity() public méthode

Returns number of items available for sale.
public get_stock_quantity ( string $context = 'view' ) : integer | null
$context string
Résultat integer | null

get_stock_status() public méthode

Return the stock status.
Since: 2.7.0
public get_stock_status ( string $context = 'view' ) : string
$context string
Résultat string

get_tag_ids() public méthode

Get tag ids.
Since: 2.7.0
public get_tag_ids ( string $context = 'view' ) : array
$context string
Résultat array

get_tax_class() public méthode

Returns the tax class.
public get_tax_class ( string $context = 'view' ) : string
$context string
Résultat string

get_tax_status() public méthode

Returns the tax status.
public get_tax_status ( string $context = 'view' ) : string
$context string
Résultat string

get_title() public méthode

Get the product's title. For products this is the product name.
public get_title ( ) : string
Résultat string

get_total_sales() public méthode

Get number total of sales.
Since: 2.7.0
public get_total_sales ( string $context = 'view' ) : integer
$context string
Résultat integer

get_type() public méthode

Get internal type. Should return string and *should be overridden* by child classes.
Since: 2.7.0
public get_type ( ) : string
Résultat string

get_upsell_ids() public méthode

Get upsel IDs.
Since: 2.7.0
public get_upsell_ids ( string $context = 'view' ) : array
$context string
Résultat array

get_virtual() public méthode

Get virtual.
Since: 2.7.0
public get_virtual ( string $context = 'view' ) : boolean
$context string
Résultat boolean

get_weight() public méthode

Returns the product's weight.
public get_weight ( string $context = 'view' ) : string
$context string
Résultat string

get_width() public méthode

Returns the product width.
public get_width ( string $context = 'view' ) : string
$context string
Résultat string

has_attributes() public méthode

Returns whether or not the product has any visible attributes.
public has_attributes ( ) : boolean
Résultat boolean

has_child() public méthode

Returns whether or not the product has any child product.
public has_child ( ) : boolean
Résultat boolean

has_dimensions() public méthode

Returns whether or not the product has dimensions set.
public has_dimensions ( ) : boolean
Résultat boolean

has_enough_stock() public méthode

Returns whether or not the product has enough stock for the order.
public has_enough_stock ( mixed $quantity ) : boolean
$quantity mixed
Résultat boolean

has_file() public méthode

Check if downloadable product has a file attached.
Since: 1.6.2
public has_file ( string $download_id = '' ) : boolean
$download_id string file identifier
Résultat boolean Whether downloadable product has a file attached.

has_weight() public méthode

Returns whether or not the product has weight set.
public has_weight ( ) : boolean
Résultat boolean

is_downloadable() public méthode

Checks if a product is downloadable.
public is_downloadable ( ) : boolean
Résultat boolean

is_in_stock() public méthode

Returns whether or not the product is in stock.
public is_in_stock ( ) : boolean
Résultat boolean

is_on_backorder() public méthode

Check if a product is on backorder.
public is_on_backorder ( integer $qty_in_cart ) : boolean
$qty_in_cart integer (default: 0)
Résultat boolean

is_on_sale() public méthode

Returns whether or not the product is on sale.
public is_on_sale ( ) : boolean
Résultat boolean

is_purchasable() public méthode

Returns false if the product cannot be bought.
public is_purchasable ( ) : boolean
Résultat boolean

is_shipping_taxable() public méthode

Returns whether or not the product shipping is taxable.
public is_shipping_taxable ( ) : boolean
Résultat boolean

is_sold_individually() public méthode

Check if a product is sold individually (no quantities).
public is_sold_individually ( ) : boolean
Résultat boolean

is_taxable() public méthode

Returns whether or not the product is taxable.
public is_taxable ( ) : boolean
Résultat boolean

is_type() public méthode

Backwards compat with downloadable/virtual.
public is_type ( string $type ) : boolean
$type string Array or string of types
Résultat boolean

is_virtual() public méthode

Checks if a product is virtual (has no shipping).
public is_virtual ( ) : boolean
Résultat boolean

is_visible() public méthode

Returns whether or not the product is visible in the catalog.
public is_visible ( ) : boolean
Résultat boolean

managing_stock() public méthode

Returns whether or not the product is stock managed.
public managing_stock ( ) : boolean
Résultat boolean

needs_shipping() public méthode

Checks if a product needs shipping.
public needs_shipping ( ) : boolean
Résultat boolean

sanitize_term_ids() protected méthode

Get term ids from either a list of names, ids, or terms.
Since: 2.7.0
protected sanitize_term_ids ( array $terms, string $taxonomy )
$terms array
$taxonomy string

save() public méthode

Save data (either create or update depending on if we are working on an existing product).
Since: 2.7.0
public save ( )

set_attributes() public méthode

Attributes are made up of: id - 0 for product level attributes. ID for global attributes. name - Attribute name. options - attribute value or array of term ids/names. position - integer sort order. visible - If visible on frontend. variation - If used for variations. Indexed by unqiue key to allow clearing old ones after a set.
Since: 2.7.0
public set_attributes ( array $raw_attributes )
$raw_attributes array Array of WC_Product_Attribute objects.

set_average_rating() public méthode

Set average rating. Read only.
public set_average_rating ( float $average )
$average float

set_backorders() public méthode

Set backorders.
Since: 2.7.0
public set_backorders ( string $backorders )
$backorders string Options: 'yes', 'no' or 'notify'.

set_catalog_visibility() public méthode

Set catalog visibility.
Since: 2.7.0
public set_catalog_visibility ( string $visibility )
$visibility string Options: 'hidden', 'visible', 'search' and 'catalog'.

set_category_ids() public méthode

Set the product categories.
Since: 2.7.0
public set_category_ids ( array $term_ids )
$term_ids array List of terms IDs.

set_cross_sell_ids() public méthode

Set crosssell IDs.
Since: 2.7.0
public set_cross_sell_ids ( array $cross_sell_ids )
$cross_sell_ids array IDs from the cross-sell products.

set_date_created() public méthode

Set product created date.
Since: 2.7.0
public set_date_created ( string $timestamp )
$timestamp string Timestamp.

set_date_modified() public méthode

Set product modified date.
Since: 2.7.0
public set_date_modified ( string $timestamp )
$timestamp string Timestamp.

set_date_on_sale_from() public méthode

Set date on sale from.
Since: 2.7.0
public set_date_on_sale_from ( string $timestamp )
$timestamp string Sale from date.

set_date_on_sale_to() public méthode

Set date on sale to.
Since: 2.7.0
public set_date_on_sale_to ( string $timestamp )
$timestamp string Sale to date.

set_default_attributes() public méthode

Set default attributes.
Since: 2.7.0
public set_default_attributes ( array $default_attributes )
$default_attributes array List of default attributes.

set_description() public méthode

Set product description.
Since: 2.7.0
public set_description ( string $description )
$description string Product description.

set_download_expiry() public méthode

Set download expiry.
Since: 2.7.0
public set_download_expiry ( integer $download_expiry )
$download_expiry integer

set_download_limit() public méthode

Set download limit.
Since: 2.7.0
public set_download_limit ( integer $download_limit )
$download_limit integer

set_downloadable() public méthode

Set if the product is downloadable.
Since: 2.7.0
public set_downloadable ( $downloadable )

set_downloads() public méthode

Set downloads.
Since: 2.7.0
public set_downloads ( $downloads_array )
$downloads_array array of WC_Product_Download objects or arrays.

set_height() public méthode

Set the product height.
Since: 2.7.0
public set_height ( float | string $height )
$height float | string Total height.

set_image_id() public méthode

Set main image ID.
Since: 2.7.0
public set_image_id ( integer $image_id = '' )
$image_id integer

set_length() public méthode

Set the product length.
Since: 2.7.0
public set_length ( float | string $length )
$length float | string Total length.

set_manage_stock() public méthode

Set if product manage stock.
Since: 2.7.0
public set_manage_stock ( $manage_stock )

set_menu_order() public méthode

Set menu order.
Since: 2.7.0
public set_menu_order ( integer $menu_order )
$menu_order integer Menu order.

set_name() public méthode

Set product name.
Since: 2.7.0
public set_name ( string $name )
$name string Product name.

set_parent_id() public méthode

Set parent ID.
Since: 2.7.0
public set_parent_id ( integer $parent_id )
$parent_id integer Product parent ID.

set_price() public méthode

Set the product's active price.
public set_price ( string $price )
$price string Price.

set_purchase_note() public méthode

Set purchase note.
Since: 2.7.0
public set_purchase_note ( string $purchase_note )
$purchase_note string Purchase note.

set_rating_counts() public méthode

Set rating counts. Read only.
public set_rating_counts ( array $counts )
$counts array

set_regular_price() public méthode

Set the product's regular price.
Since: 2.7.0
public set_regular_price ( string $price )
$price string Regular price.

set_review_count() public méthode

Set review count. Read only.
public set_review_count ( integer $count )
$count integer

set_reviews_allowed() public méthode

Set if reviews is allowed.
Since: 2.7.0
public set_reviews_allowed ( boolean $reviews_allowed )
$reviews_allowed boolean Reviews allowed or not.

set_sale_price() public méthode

Set the product's sale price.
Since: 2.7.0
public set_sale_price ( string $price )
$price string sale price.

set_shipping_class_id() public méthode

Set shipping class ID.
Since: 2.7.0
public set_shipping_class_id ( $id )

set_short_description() public méthode

Set product short description.
Since: 2.7.0
public set_short_description ( string $short_description )
$short_description string Product short description.

set_sku() public méthode

Set SKU.
Since: 2.7.0
public set_sku ( string $sku )
$sku string Product SKU.

set_slug() public méthode

Set product slug.
Since: 2.7.0
public set_slug ( string $slug )
$slug string Product slug.

set_sold_individually() public méthode

Set if should be sold individually.
Since: 2.7.0
public set_sold_individually ( $sold_individually )

set_status() public méthode

Set product status.
Since: 2.7.0
public set_status ( string $status )
$status string Product status.

set_stock_quantity() public méthode

Set number of items available for sale.
Since: 2.7.0
public set_stock_quantity ( float | null $quantity )
$quantity float | null Stock quantity.

set_stock_status() public méthode

Set stock status.
public set_stock_status ( string $status = '' )
$status string New status.

set_tag_ids() public méthode

Set the product tags.
Since: 2.7.0
public set_tag_ids ( array $term_ids )
$term_ids array List of terms IDs.

set_tax_class() public méthode

Set the tax class.
Since: 2.7.0
public set_tax_class ( string $class )
$class string Tax class.

set_tax_status() public méthode

Set the tax status.
Since: 2.7.0
public set_tax_status ( string $status )
$status string Tax status.

set_total_sales() public méthode

Set number total of sales.
Since: 2.7.0
public set_total_sales ( integer $total )
$total integer Total of sales.

set_upsell_ids() public méthode

Set upsell IDs.
Since: 2.7.0
public set_upsell_ids ( array $upsell_ids )
$upsell_ids array IDs from the up-sell products.

set_virtual() public méthode

Set if the product is virtual.
Since: 2.7.0
public set_virtual ( $virtual )

set_weight() public méthode

Set the product's weight.
Since: 2.7.0
public set_weight ( float | string $weight )
$weight float | string Total weight.

set_width() public méthode

Set the product width.
Since: 2.7.0
public set_width ( float | string $width )
$width float | string Total width.

single_add_to_cart_text() public méthode

Get the add to cart button text for the single page.
public single_add_to_cart_text ( ) : string
Résultat string

supports() public méthode

Product classes should override this to declare support (or lack of support) for a feature.
Since: 2.5.0
public supports ( string $feature ) : boolean
$feature string string The name of a feature to test support for.
Résultat boolean True if the product supports the feature, false otherwise.

validate_props() public méthode

Ensure properties are set correctly before save.
Since: 2.7.0
public validate_props ( )

Property Details

$cache_group protected_oe property

Cache group.
protected string $cache_group
Résultat string

$data protected_oe property

Stores product data.
protected array $data
Résultat array

$post_type protected_oe property

Post type.
protected string $post_type
Résultat string

$supports protected_oe property

Supported features such as 'ajax_add_to_cart'.
protected array $supports
Résultat array