🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC] # WooCommerce常用的API和帮助函数 ### 1\. API #### 1.1. WC\_Product * `get_id()`:获取产品ID。 * `get_name()`:获取产品名称。 * `get_price()`:获取产品价格。 * `get_sale_price()`:获取产品折扣价。 * `get_regular_price()`:获取产品常规价。 * `get_stock_quantity()`:获取产品库存数量。 * `is_in_stock()`:检查产品是否有库存。 * `get_categories()`:获取产品分类。 * `get_tags()`:获取产品标签。 * `get_rating_count()`:获取产品评分次数。 * `get_average_rating()`:获取产品平均评分。 #### 1.2. WC\_Order * `get_id()`:获取订单ID。 * `get_status()`:获取订单状态。 * `get_total()`:获取订单总金额。 * `get_billing_first_name()`:获取订单收件人姓名。 * `get_billing_last_name()`:获取订单收件人姓氏。 * `get_billing_email()`:获取订单收件人邮箱。 * `get_billing_phone()`:获取订单收件人电话。 * `get_shipping_first_name()`:获取订单收货人姓名。 * `get_shipping_last_name()`:获取订单收货人姓氏。 * `get_shipping_address_1()`:获取订单收货地址1。 * `get_shipping_address_2()`:获取订单收货地址2。 * `get_shipping_city()`:获取订单收货城市。 * `get_shipping_state()`:获取订单收货州/省份。 * `get_shipping_postcode()`:获取订单收货邮政编码。 #### 1.3. WC\_Cart * `get_cart_contents()`:获取购物车中的产品。 * `get_cart_total()`:获取购物车中产品的总价。 * `add_to_cart()`:向购物车中添加产品。 * `remove_cart_item()`:从购物车中删除产品。 * `empty_cart()`:清空购物车。 #### 1.4. WC\_Customer * `get_id()`:获取客户ID。 * `get_billing_first_name()`:获取客户账单收件人姓名。 * `get_billing_last_name()`:获取客户账单收件人姓氏。 * `get_billing_email()`:获取客户邮箱。 * `get_billing_phone()`:获取客户电话。 * `get_shipping_first_name()`:获取客户收货人姓名。 * `get_shipping_last_name()`:获取客户收货人姓氏。 * `get_shipping_address_1()`:获取客户收货地址1。 \-`get_shipping_address_2()`:获取客户收货地址2。 * `get_shipping_city()`:获取客户收货城市。 * `get_shipping_state()`:获取客户收货州/省份。 * `get_shipping_postcode()`:获取客户收货邮政编码。 ### 2\. 帮助函数 #### 2.1. wc\_get\_product() `wc_get_product($product_id)`:根据产品ID获取产品对象。 #### 2.2. wc\_get\_order() `wc_get_order($order_id)`:根据订单ID获取订单对象。 #### 2.3. wc\_get\_order\_item\_meta() `wc_get_order_item_meta($order_item_id, $meta_key, $single = true)`:获取订单项元数据。 #### 2.4. wc\_get\_customer() `wc_get_customer($customer_id)`:根据客户ID获取客户对象。 #### 2.5. wc\_price() `wc_price($price, $args = array())`:格式化价格。 #### 2.6. wc\_get\_template() `wc_get_template($template_name, $args = array(), $template_path = '', $default_path = '')`:获取WooCommerce模板文件。