WooCommerce Product Functions
ProductWooCommerce

WooCommerce Product Functions

WooCommerce Product Functions

Table of Contents

Over 100 Functions for Retrieving and Verifying Product Information in WooCommerce

This article provides all the necessary functions for managing products in PHP, including snippets, plugins, and themes for use with the WooCommerce platform.

Get Information by product object

Get product by product Id

$product_id = 10;
$product      = wc_get_product( $product_id );

Get Product Type

echo $product_type = $product->get_type();

Get Product Name

echo $product_name = $product->get_name();

Get Product Slug

echo $product_name = $product->get_slug();

Get product Title

// Get Product title by product object.
echo $product_name = $product->get_title();
// Get product title by product id.
echo get_the_title( $product_id );

Get product children

// Get product children of variable and grouped products
$children = $product->get_children();
print_r( $children );

Get Price HTML


// Get porduct price html of variable, variation, composite, subscription and grouped product.
$price_html = $product->get_price_html();
// Get product price of simple product and display on shop.
$price_html = wc_price( wc_get_price_to_display( $product ) );
// Get product price including tax and excluding.
$incl_tax_price  = wc_get_price_including_tax( $product );
$excl_tax_price = wc_get_price_excluding_tax( $product );

$incl_tax_price_html   = wc_price( $incl_tax_price );
$excl_tax_price _html = wc_price( $incl_tax_price );

Get formatted Name

// Get product name with SKU or ID.
echo $product_formatted_name = $product->get_formatted_name();

Get Minimum Purchase Quantity

// Get min quantity which can be purchased at once.
echo $min_quantity= $product->get_min_purchase_quantity();

Get Maximum Purchase Quantity

// Get max quantity which can be purchased at once.
echo $max_quantity= $product->get_max_purchase_quantity();

Get Add to cart URL

// Get the add to url used mainly in loops
echo $product->add_to_cart_url();

Get add to cart button Text for single product page

echo $product->single_add_to_cart_text();

Get add to cart Button Text

echo $product->add_to_cart_text();

Get Add to cart Burton text description

echo $product->add_to_cart_description();

Get Product image

echo $product->get_image( $size = 'woocommerce_thumbnail', $attr = array(), $placeholder = true );

Get product Shipping class

echo $product->get_shipping_class();

Get the Single Product attribute as a string

echo $product->get_attribute( $attribute );

Get rating count

// Get the total amount (COUNT) of ratings, or just the count for one rating e.g. number of 5 star ratings
echo $product->get_rating_count( $value = null );

Get File by download id

// Get a file by $download_id.
$file = $product->get_file( $download_id = '' );
print_r( $file );

Get file Download path

// Get file download path identified by $download_id.
echo $product->get_file_download_path( $download_id );

Get price suffix

//  Get the suffix to display after prices > 0.
echo $product->get_price_suffix( $price = '', $qty = 1 );

Get Availability of Product

// Returns the availability of the product.
$availability = $product->get_availability();
print_r( $availability );

Get availability text based on stock status

$product->get_availability_text()

Get availability class name on stock status

$product->get_availability_class();

Get Product Date of Creation

// Get product created date
$product->get_date_created();

Get Product Date of Modification

$product->get_date_modified();

Get Product Status

$product->get_status();

Get product Featured if the product is Featured

$product->get_featured();

Get product Catalog Visibility

$product->get_catalog_visibility();

Get product Description

$product->get_description();

Get Product Short Description

$product->get_short_description();

Get product SKU (Stock-keeping unit) – unique product ID.

$product->get_sku();

Get Active Product Price

$product->get_price();

Get Regular Product Price

$product->get_regular_price();

Get Product Sale Price

$product->get_active_price();

Get product Date on Sale from

$product->get_date_on_sale_from();

Get product Date on Sale to

$product->get_date_on_sale_to();

Get total sales

$product->get_total_sales();

Get Tax status

$product->get_tax_status();

Get Manage Stock (Boolean Return)

$product->get_manage_stock();

Get Stock Quantity

$product->get_stock_quantity();

Get Stock Status

$product->get_stock_status();

Get Back Orders

$product->get_backorders();

Get Low Stock Amount

$product->get_low_stock_amount();

Get sold Individually (return Boolean)

$product->get_sold_individually();

Get product Weight

$product->get_weight();

Get product Length

$product->get_length();

Get Product height

$product->get_height();

Get product dimensions (return array or wc_format_dimensions

$product->get_dimensions();

Get upsell ids

$product->get_upsell_ids();

Get cross-sell ids

$product->get_cross_sell_ids();

Get parent id

$product->get_parent_id();

Get reviews allowed (Return Boolean)

$product->get_reviews_allowed();

Get Purchase Note

$product->get_purchase_note();

Get product attributes (array)

$product->get_attributes();

Get Default Attributes (array)

$product->get_default_attributes();

Get Menu order (integer)

$product->get_menu_order();

Get Post Password

$product->get_post_password();

Get Category Ids

$product->get_category_ids();

Get Tag ids

$product->get_tag_ids();

Get virtual (return Boolean)

$product->get_virtual();

Get Gallery Attachment ids

$product->get_gallery_image_ids();

Get shipping class ids

$product->get_shipping_class_id();

Get downloads

$product->get_downloads();

Get download Expiry

$product->get_download_expiry();

Get downloadable

$product->get_downloadable();

Get download limit

$product->get_download_limit();

Get Image Id

$product->get_image_id();

Get rating count

$product->get_rating_counts();

Get Average rating

$product->get_average_rating();

Get review count

$product->get_review_count();

Classes of WooCommerce

WC_Product

WC_Product_External

WC_Product_Grouped

WC_Product_Simple

WC_Product_Variable

WC_Product_Variation