2018-09-17 14:32:03 +00:00
|
|
|
<?php
|
2018-09-18 19:41:45 +00:00
|
|
|
/**
|
|
|
|
* REST API bootstrap.
|
|
|
|
*
|
|
|
|
* @package WooCommerce Admin/Classes
|
|
|
|
*/
|
2018-09-17 14:32:03 +00:00
|
|
|
|
2019-08-02 18:05:18 +00:00
|
|
|
namespace Automattic\WooCommerce\Admin\API;
|
|
|
|
|
2018-09-18 19:41:45 +00:00
|
|
|
defined( 'ABSPATH' ) || exit;
|
2018-09-17 14:32:03 +00:00
|
|
|
|
2019-08-12 21:52:09 +00:00
|
|
|
use \Automattic\WooCommerce\Admin\Loader;
|
2019-08-12 18:11:28 +00:00
|
|
|
|
2018-09-18 19:41:45 +00:00
|
|
|
/**
|
2019-08-12 21:52:09 +00:00
|
|
|
* Init class.
|
2018-09-18 19:41:45 +00:00
|
|
|
*/
|
2019-08-12 19:34:08 +00:00
|
|
|
class Init {
|
2018-09-17 14:32:03 +00:00
|
|
|
|
2018-09-18 19:41:45 +00:00
|
|
|
/**
|
|
|
|
* Boostrap REST API.
|
|
|
|
*/
|
2018-09-17 14:32:03 +00:00
|
|
|
public function __construct() {
|
|
|
|
// Hook in data stores.
|
2019-08-02 18:05:18 +00:00
|
|
|
add_filter( 'woocommerce_data_stores', array( __CLASS__, 'add_data_stores' ) );
|
2018-09-17 14:32:03 +00:00
|
|
|
// REST API extensions init.
|
|
|
|
add_action( 'rest_api_init', array( $this, 'rest_api_init' ) );
|
2019-08-02 18:05:18 +00:00
|
|
|
add_filter( 'rest_endpoints', array( __CLASS__, 'filter_rest_endpoints' ), 10, 1 );
|
2019-01-17 07:01:09 +00:00
|
|
|
|
|
|
|
// Add currency symbol to orders endpoint response.
|
|
|
|
add_filter( 'woocommerce_rest_prepare_shop_order_object', array( __CLASS__, 'add_currency_symbol_to_order_response' ) );
|
2018-09-17 14:32:03 +00:00
|
|
|
}
|
|
|
|
|
2018-09-18 19:41:45 +00:00
|
|
|
/**
|
|
|
|
* Init REST API.
|
|
|
|
*/
|
2018-09-17 14:32:03 +00:00
|
|
|
public function rest_api_init() {
|
2019-05-31 14:55:52 +00:00
|
|
|
$controllers = array(
|
2019-08-02 18:17:59 +00:00
|
|
|
'Automattic\WooCommerce\Admin\API\Notes',
|
|
|
|
'Automattic\WooCommerce\Admin\API\NoteActions',
|
2019-08-02 18:54:09 +00:00
|
|
|
'Automattic\WooCommerce\Admin\API\Coupons',
|
|
|
|
'Automattic\WooCommerce\Admin\API\Customers',
|
|
|
|
'Automattic\WooCommerce\Admin\API\Data',
|
|
|
|
'Automattic\WooCommerce\Admin\API\DataCountries',
|
|
|
|
'Automattic\WooCommerce\Admin\API\DataDownloadIPs',
|
|
|
|
'Automattic\WooCommerce\Admin\API\Leaderboards',
|
|
|
|
'Automattic\WooCommerce\Admin\API\Orders',
|
|
|
|
'Automattic\WooCommerce\Admin\API\Products',
|
|
|
|
'Automattic\WooCommerce\Admin\API\ProductCategories',
|
|
|
|
'Automattic\WooCommerce\Admin\API\ProductVariations',
|
|
|
|
'Automattic\WooCommerce\Admin\API\ProductReviews',
|
|
|
|
'Automattic\WooCommerce\Admin\API\ProductVariations',
|
2019-08-03 02:26:35 +00:00
|
|
|
'Automattic\WooCommerce\Admin\API\Reports\Controller',
|
2019-08-02 18:54:09 +00:00
|
|
|
'Automattic\WooCommerce\Admin\API\SettingOptions',
|
2019-08-03 02:26:35 +00:00
|
|
|
'Automattic\WooCommerce\Admin\API\Reports\Import\Controller',
|
|
|
|
'Automattic\WooCommerce\Admin\API\Reports\Export\Controller',
|
|
|
|
'Automattic\WooCommerce\Admin\API\Reports\Products\Controller',
|
|
|
|
'Automattic\WooCommerce\Admin\API\Reports\Variations\Controller',
|
|
|
|
'Automattic\WooCommerce\Admin\API\Reports\Products\Stats\Controller',
|
|
|
|
'Automattic\WooCommerce\Admin\API\Reports\Revenue\Stats\Controller',
|
|
|
|
'Automattic\WooCommerce\Admin\API\Reports\Orders\Controller',
|
|
|
|
'Automattic\WooCommerce\Admin\API\Reports\Orders\Stats\Controller',
|
|
|
|
'Automattic\WooCommerce\Admin\API\Reports\Categories\Controller',
|
|
|
|
'Automattic\WooCommerce\Admin\API\Reports\Taxes\Controller',
|
|
|
|
'Automattic\WooCommerce\Admin\API\Reports\Taxes\Stats\Controller',
|
|
|
|
'Automattic\WooCommerce\Admin\API\Reports\Coupons\Controller',
|
|
|
|
'Automattic\WooCommerce\Admin\API\Reports\Coupons\Stats\Controller',
|
|
|
|
'Automattic\WooCommerce\Admin\API\Reports\Stock\Controller',
|
|
|
|
'Automattic\WooCommerce\Admin\API\Reports\Stock\Stats\Controller',
|
|
|
|
'Automattic\WooCommerce\Admin\API\Reports\Downloads\Controller',
|
|
|
|
'Automattic\WooCommerce\Admin\API\Reports\Downloads\Stats\Controller',
|
|
|
|
'Automattic\WooCommerce\Admin\API\Reports\Customers\Controller',
|
|
|
|
'Automattic\WooCommerce\Admin\API\Reports\Customers\Stats\Controller',
|
2019-08-02 18:54:09 +00:00
|
|
|
'Automattic\WooCommerce\Admin\API\Taxes',
|
|
|
|
'Automattic\WooCommerce\Admin\API\Themes',
|
2018-09-17 14:32:03 +00:00
|
|
|
);
|
|
|
|
|
2019-08-12 21:52:09 +00:00
|
|
|
if ( Loader::is_feature_enabled( 'onboarding' ) ) {
|
2019-05-31 14:55:52 +00:00
|
|
|
$controllers = array_merge(
|
|
|
|
$controllers,
|
|
|
|
array(
|
2019-08-02 18:54:09 +00:00
|
|
|
'Automattic\WooCommerce\Admin\API\OnboardingLevels',
|
|
|
|
'Automattic\WooCommerce\Admin\API\OnboardingProfile',
|
|
|
|
'Automattic\WooCommerce\Admin\API\OnboardingPlugins',
|
2019-05-31 14:55:52 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-01-09 21:08:39 +00:00
|
|
|
// The performance indicators controller must be registered last, after other /stats endpoints have been registered.
|
2019-08-03 02:26:35 +00:00
|
|
|
$controllers[] = 'Automattic\WooCommerce\Admin\API\Reports\PerformanceIndicators\Controller';
|
2019-01-09 21:08:39 +00:00
|
|
|
|
2019-05-31 14:55:52 +00:00
|
|
|
$controllers = apply_filters( 'woocommerce_admin_rest_controllers', $controllers );
|
|
|
|
|
2018-09-17 14:32:03 +00:00
|
|
|
foreach ( $controllers as $controller ) {
|
|
|
|
$this->$controller = new $controller();
|
|
|
|
$this->$controller->register_routes();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-18 19:41:45 +00:00
|
|
|
/**
|
|
|
|
* Filter REST API endpoints.
|
|
|
|
*
|
|
|
|
* @param array $endpoints List of endpoints.
|
|
|
|
* @return array
|
|
|
|
*/
|
2018-09-18 10:24:43 +00:00
|
|
|
public static function filter_rest_endpoints( $endpoints ) {
|
2019-01-18 02:52:58 +00:00
|
|
|
// Override GET /wc/v4/system_status/tools.
|
|
|
|
if ( isset( $endpoints['/wc/v4/system_status/tools'] )
|
|
|
|
&& isset( $endpoints['/wc/v4/system_status/tools'][1] )
|
|
|
|
&& isset( $endpoints['/wc/v4/system_status/tools'][0] )
|
|
|
|
&& $endpoints['/wc/v4/system_status/tools'][1]['callback'][0] instanceof WC_Admin_REST_System_Status_Tools_Controller
|
2018-09-18 10:24:43 +00:00
|
|
|
) {
|
2019-01-18 02:52:58 +00:00
|
|
|
$endpoints['/wc/v4/system_status/tools'][0] = $endpoints['/wc/v4/system_status/tools'][1];
|
2018-09-18 10:24:43 +00:00
|
|
|
}
|
2019-01-18 02:52:58 +00:00
|
|
|
// // Override GET & PUT for /wc/v4/system_status/tools.
|
|
|
|
if ( isset( $endpoints['/wc/v4/system_status/tools/(?P<id>[\w-]+)'] )
|
|
|
|
&& isset( $endpoints['/wc/v4/system_status/tools/(?P<id>[\w-]+)'][3] )
|
|
|
|
&& isset( $endpoints['/wc/v4/system_status/tools/(?P<id>[\w-]+)'][2] )
|
|
|
|
&& $endpoints['/wc/v4/system_status/tools/(?P<id>[\w-]+)'][2]['callback'][0] instanceof WC_Admin_REST_System_Status_Tools_Controller
|
|
|
|
&& $endpoints['/wc/v4/system_status/tools/(?P<id>[\w-]+)'][3]['callback'][0] instanceof WC_Admin_REST_System_Status_Tools_Controller
|
2018-09-18 10:24:43 +00:00
|
|
|
) {
|
2019-01-18 02:52:58 +00:00
|
|
|
$endpoints['/wc/v4/system_status/tools/(?P<id>[\w-]+)'][0] = $endpoints['/wc/v4/system_status/tools/(?P<id>[\w-]+)'][2];
|
|
|
|
$endpoints['/wc/v4/system_status/tools/(?P<id>[\w-]+)'][1] = $endpoints['/wc/v4/system_status/tools/(?P<id>[\w-]+)'][3];
|
2018-09-18 10:24:43 +00:00
|
|
|
}
|
|
|
|
|
2019-01-18 02:52:58 +00:00
|
|
|
// Override GET /wc/v4/reports.
|
|
|
|
if ( isset( $endpoints['/wc/v4/reports'] )
|
|
|
|
&& isset( $endpoints['/wc/v4/reports'][1] )
|
|
|
|
&& isset( $endpoints['/wc/v4/reports'][0] )
|
|
|
|
&& $endpoints['/wc/v4/reports'][1]['callback'][0] instanceof WC_Admin_REST_Reports_Controller
|
2018-09-18 10:24:43 +00:00
|
|
|
) {
|
2019-01-18 02:52:58 +00:00
|
|
|
$endpoints['/wc/v4/reports'][0] = $endpoints['/wc/v4/reports'][1];
|
2018-09-18 10:24:43 +00:00
|
|
|
}
|
|
|
|
|
2019-01-18 02:52:58 +00:00
|
|
|
// Override /wc/v4/coupons.
|
|
|
|
if ( isset( $endpoints['/wc/v4/coupons'] )
|
|
|
|
&& isset( $endpoints['/wc/v4/coupons'][3] )
|
|
|
|
&& isset( $endpoints['/wc/v4/coupons'][2] )
|
2019-08-02 18:54:09 +00:00
|
|
|
&& $endpoints['/wc/v4/coupons'][2]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Orders
|
|
|
|
&& $endpoints['/wc/v4/coupons'][3]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Orders
|
2018-12-17 16:20:11 +00:00
|
|
|
) {
|
2019-01-18 02:52:58 +00:00
|
|
|
$endpoints['/wc/v4/coupons'][0] = $endpoints['/wc/v4/coupons'][2];
|
|
|
|
$endpoints['/wc/v4/coupons'][1] = $endpoints['/wc/v4/coupons'][3];
|
2018-12-17 16:20:11 +00:00
|
|
|
}
|
|
|
|
|
2019-01-18 02:52:58 +00:00
|
|
|
// Override /wc/v4/customers.
|
|
|
|
if ( isset( $endpoints['/wc/v4/customers'] )
|
|
|
|
&& isset( $endpoints['/wc/v4/customers'][3] )
|
|
|
|
&& isset( $endpoints['/wc/v4/customers'][2] )
|
2019-08-02 18:54:09 +00:00
|
|
|
&& $endpoints['/wc/v4/customers'][2]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Customers
|
|
|
|
&& $endpoints['/wc/v4/customers'][3]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Customers
|
2018-12-22 00:40:41 +00:00
|
|
|
) {
|
2019-01-18 02:52:58 +00:00
|
|
|
$endpoints['/wc/v4/customers'][0] = $endpoints['/wc/v4/customers'][2];
|
|
|
|
$endpoints['/wc/v4/customers'][1] = $endpoints['/wc/v4/customers'][3];
|
2018-12-22 00:40:41 +00:00
|
|
|
}
|
|
|
|
|
2019-01-18 02:52:58 +00:00
|
|
|
// Override /wc/v4/orders/$id.
|
|
|
|
if ( isset( $endpoints['/wc/v4/orders/(?P<id>[\d]+)'] )
|
|
|
|
&& isset( $endpoints['/wc/v4/orders/(?P<id>[\d]+)'][5] )
|
|
|
|
&& isset( $endpoints['/wc/v4/orders/(?P<id>[\d]+)'][4] )
|
|
|
|
&& isset( $endpoints['/wc/v4/orders/(?P<id>[\d]+)'][3] )
|
2019-08-02 18:54:09 +00:00
|
|
|
&& $endpoints['/wc/v4/orders/(?P<id>[\d]+)'][3]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Orders
|
|
|
|
&& $endpoints['/wc/v4/orders/(?P<id>[\d]+)'][4]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Orders
|
|
|
|
&& $endpoints['/wc/v4/orders/(?P<id>[\d]+)'][5]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Orders
|
2018-12-22 00:40:41 +00:00
|
|
|
) {
|
2019-01-18 02:52:58 +00:00
|
|
|
$endpoints['/wc/v4/orders/(?P<id>[\d]+)'][0] = $endpoints['/wc/v4/orders/(?P<id>[\d]+)'][3];
|
|
|
|
$endpoints['/wc/v4/orders/(?P<id>[\d]+)'][1] = $endpoints['/wc/v4/orders/(?P<id>[\d]+)'][4];
|
|
|
|
$endpoints['/wc/v4/orders/(?P<id>[\d]+)'][2] = $endpoints['/wc/v4/orders/(?P<id>[\d]+)'][5];
|
2018-12-22 00:40:41 +00:00
|
|
|
}
|
|
|
|
|
2019-01-18 02:52:58 +00:00
|
|
|
// Override /wc/v4/orders.
|
|
|
|
if ( isset( $endpoints['/wc/v4/orders'] )
|
|
|
|
&& isset( $endpoints['/wc/v4/orders'][3] )
|
|
|
|
&& isset( $endpoints['/wc/v4/orders'][2] )
|
2019-08-02 18:54:09 +00:00
|
|
|
&& $endpoints['/wc/v4/orders'][2]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Orders
|
|
|
|
&& $endpoints['/wc/v4/orders'][3]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Orders
|
2018-12-22 00:40:41 +00:00
|
|
|
) {
|
2019-01-18 02:52:58 +00:00
|
|
|
$endpoints['/wc/v4/orders'][0] = $endpoints['/wc/v4/orders'][2];
|
|
|
|
$endpoints['/wc/v4/orders'][1] = $endpoints['/wc/v4/orders'][3];
|
2018-12-22 00:40:41 +00:00
|
|
|
}
|
|
|
|
|
2019-01-18 02:52:58 +00:00
|
|
|
// Override /wc/v4/data.
|
|
|
|
if ( isset( $endpoints['/wc/v4/data'] )
|
|
|
|
&& isset( $endpoints['/wc/v4/data'][1] )
|
2019-08-02 18:54:09 +00:00
|
|
|
&& $endpoints['/wc/v4/data'][1]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Data
|
2018-12-22 00:40:41 +00:00
|
|
|
) {
|
2019-01-18 02:52:58 +00:00
|
|
|
$endpoints['/wc/v4/data'][0] = $endpoints['/wc/v4/data'][1];
|
2018-12-22 00:40:41 +00:00
|
|
|
}
|
|
|
|
|
2019-01-18 02:52:58 +00:00
|
|
|
// Override /wc/v4/products.
|
|
|
|
if ( isset( $endpoints['/wc/v4/products'] )
|
|
|
|
&& isset( $endpoints['/wc/v4/products'][3] )
|
|
|
|
&& isset( $endpoints['/wc/v4/products'][2] )
|
2019-08-02 18:54:09 +00:00
|
|
|
&& $endpoints['/wc/v4/products'][2]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Products
|
|
|
|
&& $endpoints['/wc/v4/products'][3]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Products
|
2018-12-12 13:35:56 +00:00
|
|
|
) {
|
2019-01-18 02:52:58 +00:00
|
|
|
$endpoints['/wc/v4/products'][0] = $endpoints['/wc/v4/products'][2];
|
|
|
|
$endpoints['/wc/v4/products'][1] = $endpoints['/wc/v4/products'][3];
|
2018-12-12 13:35:56 +00:00
|
|
|
}
|
|
|
|
|
2019-01-18 02:52:58 +00:00
|
|
|
// Override /wc/v4/products/$id.
|
|
|
|
if ( isset( $endpoints['/wc/v4/products/(?P<id>[\d]+)'] )
|
|
|
|
&& isset( $endpoints['/wc/v4/products/(?P<id>[\d]+)'][5] )
|
|
|
|
&& isset( $endpoints['/wc/v4/products/(?P<id>[\d]+)'][4] )
|
|
|
|
&& isset( $endpoints['/wc/v4/products/(?P<id>[\d]+)'][3] )
|
2019-08-02 18:54:09 +00:00
|
|
|
&& $endpoints['/wc/v4/products/(?P<id>[\d]+)'][3]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Products
|
|
|
|
&& $endpoints['/wc/v4/products/(?P<id>[\d]+)'][4]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Products
|
|
|
|
&& $endpoints['/wc/v4/products/(?P<id>[\d]+)'][5]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Products
|
2018-12-12 13:35:56 +00:00
|
|
|
) {
|
2019-01-18 02:52:58 +00:00
|
|
|
$endpoints['/wc/v4/products/(?P<id>[\d]+)'][0] = $endpoints['/wc/v4/products/(?P<id>[\d]+)'][3];
|
|
|
|
$endpoints['/wc/v4/products/(?P<id>[\d]+)'][1] = $endpoints['/wc/v4/products/(?P<id>[\d]+)'][4];
|
|
|
|
$endpoints['/wc/v4/products/(?P<id>[\d]+)'][2] = $endpoints['/wc/v4/products/(?P<id>[\d]+)'][5];
|
|
|
|
}
|
|
|
|
|
2019-01-21 17:12:00 +00:00
|
|
|
// Override /wc/v4/products/categories.
|
|
|
|
if ( isset( $endpoints['/wc/v4/products/categories'] )
|
|
|
|
&& isset( $endpoints['/wc/v4/products/categories'][3] )
|
|
|
|
&& isset( $endpoints['/wc/v4/products/categories'][2] )
|
2019-08-02 18:54:09 +00:00
|
|
|
&& $endpoints['/wc/v4/products/categories'][2]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\ProductCategories
|
|
|
|
&& $endpoints['/wc/v4/products/categories'][3]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\ProductCategories
|
2019-01-21 17:12:00 +00:00
|
|
|
) {
|
|
|
|
$endpoints['/wc/v4/products/categories'][0] = $endpoints['/wc/v4/products/categories'][2];
|
|
|
|
$endpoints['/wc/v4/products/categories'][1] = $endpoints['/wc/v4/products/categories'][3];
|
|
|
|
}
|
|
|
|
|
2019-01-18 02:52:58 +00:00
|
|
|
// Override /wc/v4/products/reviews.
|
|
|
|
if ( isset( $endpoints['/wc/v4/products/reviews'] )
|
|
|
|
&& isset( $endpoints['/wc/v4/products/reviews'][3] )
|
|
|
|
&& isset( $endpoints['/wc/v4/products/reviews'][2] )
|
2019-08-02 18:54:09 +00:00
|
|
|
&& $endpoints['/wc/v4/products/reviews'][2]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\ProductReviews
|
|
|
|
&& $endpoints['/wc/v4/products/reviews'][3]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\ProductReviews
|
2019-01-18 02:52:58 +00:00
|
|
|
) {
|
|
|
|
$endpoints['/wc/v4/products/reviews'][0] = $endpoints['/wc/v4/products/reviews'][2];
|
|
|
|
$endpoints['/wc/v4/products/reviews'][1] = $endpoints['/wc/v4/products/reviews'][3];
|
2018-12-12 13:35:56 +00:00
|
|
|
}
|
|
|
|
|
2019-02-04 02:49:58 +00:00
|
|
|
// Override /wc/v4/products/$product_id/variations.
|
|
|
|
if ( isset( $endpoints['products/(?P<product_id>[\d]+)/variations'] )
|
|
|
|
&& isset( $endpoints['products/(?P<product_id>[\d]+)/variations'][3] )
|
|
|
|
&& isset( $endpoints['products/(?P<product_id>[\d]+)/variations'][2] )
|
2019-08-02 18:54:09 +00:00
|
|
|
&& $endpoints['products/(?P<product_id>[\d]+)/variations'][2]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\ProductVariations
|
|
|
|
&& $endpoints['products/(?P<product_id>[\d]+)/variations'][3]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\ProductVariations
|
2019-02-04 02:49:58 +00:00
|
|
|
) {
|
|
|
|
$endpoints['products/(?P<product_id>[\d]+)/variations'][0] = $endpoints['products/(?P<product_id>[\d]+)/variations'][2];
|
|
|
|
$endpoints['products/(?P<product_id>[\d]+)/variations'][1] = $endpoints['products/(?P<product_id>[\d]+)/variations'][3];
|
|
|
|
}
|
|
|
|
|
2019-01-30 09:43:30 +00:00
|
|
|
// Override /wc/v4/taxes.
|
|
|
|
if ( isset( $endpoints['/wc/v4/taxes'] )
|
|
|
|
&& isset( $endpoints['/wc/v4/taxes'][3] )
|
|
|
|
&& isset( $endpoints['/wc/v4/taxes'][2] )
|
2019-08-02 18:54:09 +00:00
|
|
|
&& $endpoints['/wc/v4/taxes'][2]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Orders
|
|
|
|
&& $endpoints['/wc/v4/taxes'][3]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\Orders
|
2019-01-30 09:43:30 +00:00
|
|
|
) {
|
|
|
|
$endpoints['/wc/v4/taxes'][0] = $endpoints['/wc/v4/taxes'][2];
|
|
|
|
$endpoints['/wc/v4/taxes'][1] = $endpoints['/wc/v4/taxes'][3];
|
|
|
|
}
|
|
|
|
|
2019-01-31 01:04:11 +00:00
|
|
|
// Override /wc/v4/settings/$group_id.
|
|
|
|
if ( isset( $endpoints['/wc/v4/settings/(?P<group_id>[\w-]+)'] )
|
|
|
|
&& isset( $endpoints['/wc/v4/settings/(?P<group_id>[\w-]+)'][5] )
|
|
|
|
&& isset( $endpoints['/wc/v4/settings/(?P<group_id>[\w-]+)'][4] )
|
|
|
|
&& isset( $endpoints['/wc/v4/settings/(?P<group_id>[\w-]+)'][3] )
|
2019-08-02 18:54:09 +00:00
|
|
|
&& $endpoints['/wc/v4/settings/(?P<group_id>[\w-]+)'][3]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\SettingOptions
|
|
|
|
&& $endpoints['/wc/v4/settings/(?P<group_id>[\w-]+)'][4]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\SettingOptions
|
|
|
|
&& $endpoints['/wc/v4/settings/(?P<group_id>[\w-]+)'][5]['callback'][0] instanceof \Automattic\WooCommerce\Admin\API\SettingOptions
|
2019-01-31 01:04:11 +00:00
|
|
|
) {
|
|
|
|
$endpoints['/wc/v4/settings/(?P<group_id>[\w-]+)'][0] = $endpoints['/wc/v4/settings/(?P<group_id>[\w-]+)'][3];
|
|
|
|
$endpoints['/wc/v4/settings/(?P<group_id>[\w-]+)'][1] = $endpoints['/wc/v4/settings/(?P<group_id>[\w-]+)'][4];
|
|
|
|
$endpoints['/wc/v4/settings/(?P<group_id>[\w-]+)'][2] = $endpoints['/wc/v4/settings/(?P<group_id>[\w-]+)'][5];
|
|
|
|
}
|
|
|
|
|
2018-09-18 10:24:43 +00:00
|
|
|
return $endpoints;
|
|
|
|
}
|
|
|
|
|
2018-09-21 10:24:15 +00:00
|
|
|
/**
|
2018-09-18 19:41:45 +00:00
|
|
|
* Adds data stores.
|
|
|
|
*
|
|
|
|
* @param array $data_stores List of data stores.
|
|
|
|
* @return array
|
|
|
|
*/
|
2018-09-17 14:32:03 +00:00
|
|
|
public static function add_data_stores( $data_stores ) {
|
|
|
|
return array_merge(
|
|
|
|
$data_stores,
|
|
|
|
array(
|
2019-08-05 18:14:25 +00:00
|
|
|
'report-revenue-stats' => 'Automattic\WooCommerce\Admin\API\Reports\Orders\Stats\DataStore',
|
|
|
|
'report-orders' => 'Automattic\WooCommerce\Admin\API\Reports\Orders\DataStore',
|
|
|
|
'report-orders-stats' => 'Automattic\WooCommerce\Admin\API\Reports\Orders\Stats\DataStore',
|
|
|
|
'report-products' => 'Automattic\WooCommerce\Admin\API\Reports\Products\DataStore',
|
|
|
|
'report-variations' => 'Automattic\WooCommerce\Admin\API\Reports\Variations\DataStore',
|
|
|
|
'report-products-stats' => 'Automattic\WooCommerce\Admin\API\Reports\Products\Stats\DataStore',
|
|
|
|
'report-categories' => 'Automattic\WooCommerce\Admin\API\Reports\Categories\DataStore',
|
|
|
|
'report-taxes' => 'Automattic\WooCommerce\Admin\API\Reports\Taxes\DataStore',
|
|
|
|
'report-taxes-stats' => 'Automattic\WooCommerce\Admin\API\Reports\Taxes\Stats\DataStore',
|
|
|
|
'report-coupons' => 'Automattic\WooCommerce\Admin\API\Reports\Coupons\DataStore',
|
|
|
|
'report-coupons-stats' => 'Automattic\WooCommerce\Admin\API\Reports\Coupons\Stats\DataStore',
|
|
|
|
'report-downloads' => 'Automattic\WooCommerce\Admin\API\Reports\Downloads\DataStore',
|
|
|
|
'report-downloads-stats' => 'Automattic\WooCommerce\Admin\API\Reports\Downloads\Stats\DataStore',
|
|
|
|
'admin-note' => 'Automattic\WooCommerce\Admin\Notes\DataStore',
|
|
|
|
'report-customers' => 'Automattic\WooCommerce\Admin\API\Reports\Customers\DataStore',
|
|
|
|
'report-customers-stats' => 'Automattic\WooCommerce\Admin\API\Reports\Customers\Stats\DataStore',
|
|
|
|
'report-stock-stats' => 'Automattic\WooCommerce\Admin\API\Reports\Stock\Stats\DataStore',
|
2018-09-17 14:32:03 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-01-17 07:01:09 +00:00
|
|
|
/**
|
|
|
|
* Add the currency symbol (in addition to currency code) to each Order
|
|
|
|
* object in REST API responses. For use in formatCurrency().
|
|
|
|
*
|
|
|
|
* @param {WP_REST_Response} $response REST response object.
|
|
|
|
* @returns {WP_REST_Response}
|
|
|
|
*/
|
|
|
|
public static function add_currency_symbol_to_order_response( $response ) {
|
2019-03-13 17:14:02 +00:00
|
|
|
$response_data = $response->get_data();
|
|
|
|
$currency_code = $response_data['currency'];
|
|
|
|
$currency_symbol = get_woocommerce_currency_symbol( $currency_code );
|
2019-01-17 07:01:09 +00:00
|
|
|
$response_data['currency_symbol'] = html_entity_decode( $currency_symbol );
|
|
|
|
$response->set_data( $response_data );
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
2018-09-17 14:32:03 +00:00
|
|
|
}
|