There are many functions available in WooCommerce that you can use to customize and enhance your online store. Here are some essential functions you should know.
1- Accessing functions using global $product object
Get product general info
global $product; $product->get_type(); $product->get_name(); $product->get_slug(); $product->get_date_created(); $product->get_date_modified(); $product->get_status(); $product->get_featured(); $product->get_catalog_visibility(); $product->get_description(); $product->get_short_description(); $product->get_sku(); $product->get_menu_order(); $product->get_virtual(); get_permalink($product->get_id());
Get product prices
global $product; $product->get_price(); $product->get_regular_price(); $product->get_sale_price(); $product->get_date_on_sale_from(); $product->get_date_on_sale_to(); $product->get_total_sales();
Get Product Tax, Shipping & Stock
global $product; $product->get_tax_status(); $product->get_tax_class(); $product->get_manage_stock(); $product->get_stock_quantity(); $product->get_stock_status(); $product->get_backorders(); $product->get_sold_individually(); $product->get_purchase_note(); $product->get_shipping_class_id();
Get Product Dimensions
global $product; $product->get_weight(); $product->get_length(); $product->get_width(); $product->get_height(); $product->get_dimensions();
Get Linked Products
global $product; $product->get_upsell_ids(); $product->get_cross_sell_ids(); $product->get_parent_id();
Get Product Variations and Attributes
global $product; $product->get_children(); // get variations $product->get_attributes(); $product->get_default_attributes(); $product->get_attribute( 'attribute id here' ); //get specific attribute value
Get Product Taxonomies
global $product; $product->get_categories(); $product->get_category_ids(); $product->get_tag_ids();
Get Product Downloads
global $product; $product->get_downloads(); $product->get_download_expiry(); $product->get_downloadable(); $product->get_download_limit();
Get Product Images
global $product; $product->get_image_id(); $product->get_image(); $product->get_gallery_image_ids();
Get Product Reviews
global $product; $product->get_reviews_allowed(); $product->get_rating_counts(); $product->get_average_rating(); $product->get_review_count();
2- Accessing Core Functions
Product Functions
wc_get_product(): Get a product object by its ID. wc_get_product_category_list(): Get the product's categories as a formatted string. wc_get_product_tag_list(): Get the product's tags as a formatted string. wc_product_gallery(): Display the product image gallery. wc_get_product_reviews_rating_html(): Get the HTML for displaying the product reviews rating.
Cart Functions
WC()->cart->get_cart(): Get an array of products in the cart. WC()->cart->add_to_cart(): Add a product to the cart. WC()->cart->get_cart_contents_count(): Get the total number of items in the cart. WC()->cart->get_cart_total(): Get the total cart amount.
Checkout Functions
WC()->checkout->get_checkout_url(): Get the URL of the checkout page. WC()->checkout->get_checkout_payment_url(): Get the URL of the payment page during the checkout process. WC()->checkout->get_checkout_order_received_url(): Get the URL of the order received page after successful payment.
Order Functions
wc_create_order(): Create a new order programmatically. wc_get_order(): Get an order object by its ID. wc_get_orders(): Get an array of orders based on specific parameters.
User Account Functions
wc_get_customer_orders(): Get an array of customer orders. wc_get_customer_average_spending(): Get the average spending of a customer.
Coupon Functions
wc_get_coupon_code() : Get the coupon code. wc_get_coupon_amount() : Get the coupon amount. wc_get_coupon_discount_type() : Get the coupon discount type.
General Functions
wc_price(): Format a price to the store's currency format. wc_format_decimal(): Format a decimal number based on store settings. wc_get_template_part(): Load WooCommerce template parts. wc_enqueue_js(): Enqueue JavaScript scripts. wc_enqueue_styles(): Enqueue stylesheets.