【WooCommerce】 Product Code Reference | 商品技術文章





If you would like to get an object of product, you can use function wc_get_product( $product_id )

$product = wc_get_product( $product_id )


About Product Information |Woocommerce商品資訊取得

Then you can operate $product to get information about this product.

  1. Get product name:$product->get_title() & $product->get_name() are same. But get_title() could be filter by hook woocommerce_product_title.
  2. Get product slug:$product->get_slug()
  3. Get product type:$product->get_type(), return simple, variable, grouped or external. Or any value from others extension plugins for product type.
  4. Get product created date:$product->get_date_created(), return WC_DateTime Object.
  5. Get product modified date:$product->get_date_modified(), return WC_DateTime Object.
  6. Get product status:$product->get_staus().
  7. Get product featured:$product->get_featured(), return boolean.
  8. Get product visibility:$product->get_catalog_visibility().
  9. Get product content:$product->get_description().
  10. Get product excerpt:$product->get_short_description().
  11. Get product sku:$product->get_sku().
  12. Get product final price:$product->get_price() will return number and this price is final price, means if product is on sale then return sale price.
  13. Get product regular price:$product->get_regular_price().
  14. Get product on sale price:$product->get_sale_price().
  15. Get product on sale start date:$product->get_date_on_sale_from(), return WC_DateTime Object.
  16. Get product on sale end date:$product->get_date_on_sale_to(), return WC_DateTime Object.
  17. Get product total sold:$product->get_total_sales(), return total sold of this product from orders.
  18. Get product tax status:$product->get_tax_status().
  19. Get product tax class:$product->get_tax_class().
  20. Get product stock manage status:$product->get_manage_stock(), return boolean.
  21. Get product stock quantity:$product->get_stock_quantity(), return number or null.
  22. Get product stock status:$product->get_stock_status(), return on_stock or out_of_stock.
  23. Get product backorders status:$product->get_backorders(), return yes or no. If product can be purchase when out of stock, then yes.
  24. Get product low stock amount:$product->get_low_stock_amount().
  25. Get product sold individually:$product->get_sold_individually(), return boolean.
  26. Get product size of weight:$product->get_weight().
  27. Get product size of width:$product->get_width().
  28. Get product size of length:$product->get_length().
  29. Get product size of height:$product->get_height().
  30. Get product dimensions:$product->get_dimensions(), return string or array.
  31. Get product upsell products:$product->get_upsell_ids().
  32. Get product cross sell products:$product->get_cross_sell_ids().
  33. Get product parent id:$product->get_parent_id(), return number if this product is variation.
  34. Get product reviews status:$product->get_reviews_allowed(), return bool.
  35. Get product purchase note:$product->get_purchase_note().
  36. Get product attributes:$product->get_attributes(), return Array of WC_Product_Attribute.
  37. Get product default attributes:$product->get_default_attributes(), return Array of WC_Product_Attribute.
  38. Get product sort number:$product->get_menu_order().
  39. Get product password:$product->get_post_password().
  40. Get product categories:$product->get_category_ids().
  41. Get product tags:$product->get_tag_ids().
  42. Get product virtual:$product->get_virtual(), return bool.
  43. Get product gallery images:$product->get_gallery_image_ids().
  44. Get product featured image:$product->get_image_id().
  45. Get product shipping class:$product->get_shipping_class_id().
  46. Get product how many downloads:$product->get_downloads().
  47. Get product download expiry date:$product->get_download_expiry(), return timestamp.
  48. Get product downloadable status:$product->get_downloadable(), return bool.
  49. Get product download limit:$product->get_download_limit().
  50. Get product rating counts:$product->get_rating_counts().
  51. Get product average rating:$product->get_average_rating().
  52. Get product review count:$product->get_review_count().



本網站 Woocommerce技術文章系列,是來自 創意數位科技團隊 的小小筆記…


分享在 facebook
分享在 twitter