redooc/woocommerce-api

使用命名空间编写的WooCommerce API客户端

v2.x-dev 2018-04-04 07:23 UTC

This package is not auto-updated.

Last update: 2024-09-19 12:22:19 UTC


README

关于

PHP封装WooCommerce REST API。使用这个封装类可以轻松与WooCommerce REST API交互。欢迎提供反馈和错误报告。

要求

PHP 5.2.x cURL WooCommerce 2.1 至少在商店中使用

开始使用

在您想要交互的商店的个人信息页面上生成API凭证(客户端密钥和客户端密钥)。

一个好的开始是查看包含的示例脚本。

初始化类

<?php
    require_once 'class-wc-api-client.php';

    $consumer_key = 'ck_fcedaba8f0fcb0fb4ae4f1211a75da72'; // Add your own Consumer Key here
	$consumer_secret = 'cs_9914968ae9adafd3741c818bf6d704c7'; // Add your own Consumer Secret here
	$store_url = 'https:///'; // Add the home URL to the store you want to connect to here

	// Initialize the class
	$wc_api = new WC_API_Client( $consumer_key, $consumer_secret, $store_url );
?>

使用方法获取数据

<?php
	// Get all orders
	$orders = $wc_api->get_orders();
	print_r( $orders );
?>

所有方法默认返回由 json_decode() 解析的数据,因此您可以访问数据。

可用方法

索引方法

  • get_index()

订单方法

  • get_orders()
  • get_orders( $params = array( 'status' => 'completed' ) )
  • get_order( $order_id )
  • get_orders_count()
  • get_order_notes( $order_id )
  • update_order( $order_id, $data = array( 'status' => 'processing' ) )
  • update_order( $order_id, $data = array( 'status' => 'processing', 'note' => 'This is a note') )

优惠券方法

  • get_coupons()
  • get_coupon( $coupon_id )
  • get_coupon_by_code( $coupon_code )
  • get_coupons_count()

客户方法

  • get_customers()
  • get_customers( $params = array( 'filter[created_at_min]' => '2013-12-01' ) )
  • get_customer( $customer_id )
  • get_customers_count()
  • get_customer_orders( $customer_id )

产品方法

  • get_products()
  • get_products( $params = array( 'filter[created_at_min]' => '2013-12-01' ) )
  • get_product( $product_id )
  • get_products_count()
  • get_product_reviews( $product_id )

报告方法

  • get_reports()
  • get_sales_report( $params = array( 'filter[start_date]' => '2013-12-01', 'filter[end_date]' => '2013-12-09' ) )
  • get_top_sellers_report( $params = array( 'filter[limit]' = '10' ) )

自定义端点

如果您扩展了WooCommerce API以包含自己的端点,则可以使用以下函数来访问这些数据

  • make_custom_endpoint_call( $endpoint, $params = array(), $method = 'GET' )

变更日志

版本 0.3.1 - 2014-05-02

  • 修复与WC 2.1.7+的参数规范化问题

版本 0.3 - 2014-02-20

  • 在失败的cURL调用上添加HTTP错误消息

版本 0.2 - 2014-01-22

  • 添加对端点函数的筛选/参数的支持
  • 添加新的顶级卖家报告端点函数
  • 添加调用自定义端点的函数

版本 0.1 - 2013-12-10

  • 初始发布

致谢

版权 (c) 2013-2014 - Gerhard Potgieter 发布在 GPL3 许可证