WooCommerce Order 类所有Get方法,面向对象的方法获取订单数据
开发WooCommerce插件或者与第三方系统交互时,我们需要获取WooCommerce订单的数据,WooCommerce的 WC_Order 类为我们提供了获取订单各种数据的方法,下面是这些方法的列表。
如果需要新建订单设置订单数据,那么下面列表中大多数 get 方法都有对应的 set 方法,非常方便。
订单基础数据
- get_id()– 获取订单ID
- get_parent_id()– 获取父订单ID(用于退款)
- get_order_number()– 获取订单号
- get_cart_tax()– 获取购物车商品税金总额
- get_total()– 获取订单总金额
- get_status()– 获取订单状态(Pending, Processing, On-hold, Completed, Cancelled, Refunded, Failed)
- get_version()– 获取订单版本
- get_payment_method()– 获取支付方式名称
- get_payment_method_title()– 获取支付方式标题
- get_cart_hash()– 获取购物车哈希值
- get_transaction_id()– 获取交易ID
- get_recorded_sales()– 获取交易是否被记录
日期相关
- get_date_created()– 获取订单创建日期
- get_date_modified()– 获取订单最后修改日期
- get_date_paid()– 获取订单支付日期
- get_date_completed()– 订单完成日期
获取订单项目
- get_items() – 获取订单中的商品项目,返回包含- WC_Order_Item对象的数组
获取订单项目数据
- $item->get_order_id()– 获取订单ID
- $item->get_name()– 获取商品名称
- $item->get_type() – 获取商品类型
- $item->get_quantity()– 获取商品数量
- $item->get_tax_status()– 获取商品税收状态
- $item->get_tax_class()– 获取商品税类
- $item->get_order()– 获取订单对象
- $item->get_product_id()– 获取商品ID
- $item->get_variation_id()– 获取商品变体ID
- $item->get_product()– 获取商品对象
- $item->get_subtotal()– 获取商品小计
- $item->get_subtotal_tax()– 获取商品小计税金
- $item->get_total()– 获取商品总计
- $item->get_total_tax()– 获取商品总税金
- $item->get_taxes()– 获取商品税项
- $item->get_item_download_url()– 获取商品下载链接
- $item->get_item_downloads()– 获取商品关联的下载文件
获取优惠码项目
- get_coupons()– 获取订单中使用的优惠码,返回包含- WC_Order_Item_Coupon对象数组
获取优惠码项目数据
- $coupon->get_type()– 获取优惠码类型
- $coupon->get_name()– 获取优惠码名称
- $coupon->get_code()– 获取优惠码代码
- $coupon->get_discount()– 获取优惠码金额
- $coupon->get_discount_tax()– 获取优惠码税收金额
获取物流方式
- get_shipping_methods() – 获取订单的物流方式,返回包含 WC_Order_Item_Shipping对象的数组。
获取物流方式项目数据
- $shipping->get_type()– 获取物流类型
- $shipping->get_name()– 获取物流名称
- $shipping->get_method_title()– 获取物流标题
- $shipping->get_method_id()– 获取物流ID
- $shipping->get_instance_id()– 获取物流实例ID
- $shipping->get_total()– 获取物流费用总额
- $shipping->get_total_tax()– 获取物流税收总额
- $shipping->get_taxes()– 获取物流税收
- $shipping->get_tax_class()– 获取物流税收类型
获取费用项目
- get_fees()– 获取所有费用项目,返回包含- WC_Order_Item_Fee的数组。
获取费用项目数据
- $fee->get_amount()– 获取费用金额
- $fee->get_name()– 获取费用名称
- $fee->get_type()– 获取费用类型
- $fee->get_tax_class()– 获取税收种类
- $fee->get_tax_status()– 获取收税状态
- $fee->get_total()– 获取总费用
- $fee->get_total_tax()– 获取费用总税收
- $fee->get_taxes()– 获取费用税收
- $fee->get_tax_class_costs()– 获取按税种分组的项目费用
账单地址、收货地址相关
下面是获取账单地址的方法,收货地址类似,把其中的billing换成shipping即可,收货地址没有获取电子邮件的方法,如果需要,直接使用账单地址的电子邮件即可。
- get_billing_first_name()– 获取账单收件人名字
- get_billing_last_name()– 获取账单收件人姓氏
- get_formatted_billing_full_name获取格式化后的账单收件人全名
- get_billing_company()– 获取账单公司名称
- get_billing_country()– 获取账单国家
- get_billing_state()– 获取账单省份
- get_billing_city()– 获取账单城市
- get_billing_address_1()– 获取账单地址第一行
- get_billing_address_2()– 获取账单地址第二行
- get_billing_postcode()– 获取账单邮政编码
- get_formatted_billing_address获取格式化后的收件地址
- get_billing_email()– 获取账单email
- get_billing_phone()– 获取账单电话
运费相关
- get_shipping_methods()– 获取所有配送方法,一个订单中可能分开配送,可以有多个配送方法
- get_shipping_method()– 获取格式化后的配送方法
- get_shipping_address_map_url()– 获取配送地址地图链接
- get_shipping_total()– 获取配送费总额
- get_total_shipping_refunded()– 获取已退还的配送费总额
- get_shipping_tax()– 获取配送税金总额
- get_shipping_to_display()– 获取显示的配送方式
优惠券、优惠相关
- get_used_coupons()– 获取订单使用的优惠码
- get_coupon_codes()– 获取订单使用的优惠码代码
- get_coupon_discount_totals()– 获取每个优惠码减免的金额总额
- get_coupon_discount_tax_totals()– 获取每个优惠码减免税金总额
- get_discount_total()– 获取的总折扣金额
- get_total_discount()– 获取的总折扣金额,可以设置是否包含收费折扣
用户相关
- get_user()– 获取下单的用户对象,如为访客,返回 false
- get_user_id()– 获取下单的用户ID,如为访客,返回 0
顾客相关
- get_customer_order_notes()– 获取与顾客相关的订单备注
- get_customer_note()– 获取顾客随订单提交的订单备注
- get_customer_id()– 获取与顾客ID
- get_customer_ip_address()– 获取顾客下单时的IP地址
- get_customer_user_agent()– 获取与顾客下单时的 user agent
退款相关
- get_reason()– 获取退款原因
- get_refunds()– 获取退款项目
- get_refunded_by()– 获取操作退款的用户ID
- get_refunded_payment()– 获取退款支付方式
- get_remaining_refund_items()– 获取剩余的退款项目
- get_remaining_refund_amount()– 获取剩余的退款金额
- get_formatted_refund_amount()– 获取格式化的退款金额
- get_qty_refunded_for_item()– 获取某个商品的退款数量
- get_tax_refunded_for_item()– 获取某个商品的退税金额
- get_total_refunded_for_item()– 获取某个商品的退款总额
URL 相关
- get_checkout_payment_url()– 获取结帐支付URL
- get_cancel_order_url()– 获取取消订单URL
- get_edit_order_url()– 获取编辑订单URL
- get_view_order_url()– 获取查看订单URL
- get_download_url()– 获取下载URL
- get_shipping_address_map_url()– 获取收货地址地图URL
- get_checkout_order_received_url()– 获取订单提交成功URL
获取自定义字段数据
- get_meta()– 获取某一些自定义字段数据
- get_meta_data()– 获取所有自定义字段数据
上面是截止WooCommerce7.6,WooCommerce订单所有 get 方法的列表。
        THE END
    
        
        



