Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "woocommerce-rest-api",
"title": "WooCommerce REST API",
"version": "1.0.10",
"version": "1.0.10-pl-2",
"homepage": "https://woocommerce.com/",
"repository": {
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ public function get_item_schema() {
),
'value' => array(
'description' => __( 'Meta value.', 'woocommerce-rest-api' ),
'type' => array( 'string', 'null' ),
'type' => 'mixed',
'context' => array( 'view', 'edit' ),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ public function get_item_schema() {
),
'value' => array(
'description' => __( 'Meta value.', 'woocommerce-rest-api' ),
'type' => array( 'string', 'null' ),
'type' => 'mixed',
'context' => array( 'view', 'edit' ),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ public function get_item_schema() {
),
'value' => array(
'description' => __( 'Meta value.', 'woocommerce-rest-api' ),
'type' => array( 'string', 'null' ),
'type' => 'mixed',
'context' => array( 'view', 'edit' ),
),
),
Expand All @@ -432,13 +432,13 @@ public function get_item_schema() {
),
'name' => array(
'description' => __( 'Product name.', 'woocommerce-rest-api' ),
'type' => array( 'string', 'null' ),
'type' => 'mixed',
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
'product_id' => array(
'description' => __( 'Product ID.', 'woocommerce-rest-api' ),
'type' => array( 'integer', 'null' ),
'type' => 'mixed',
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
Expand Down Expand Up @@ -535,7 +535,7 @@ public function get_item_schema() {
),
'value' => array(
'description' => __( 'Meta value.', 'woocommerce-rest-api' ),
'type' => array( 'string', 'null' ),
'type' => 'mixed',
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
Expand Down
24 changes: 12 additions & 12 deletions src/Controllers/Version2/class-wc-rest-orders-v2-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@ public function get_item_schema() {
),
'value' => array(
'description' => __( 'Meta value.', 'woocommerce-rest-api' ),
'type' => array( 'string', 'null' ),
'type' => 'mixed',
'context' => array( 'view', 'edit' ),
),
),
Expand All @@ -1191,12 +1191,12 @@ public function get_item_schema() {
),
'name' => array(
'description' => __( 'Product name.', 'woocommerce-rest-api' ),
'type' => array( 'string', 'null' ),
'type' => 'mixed',
'context' => array( 'view', 'edit' ),
),
'product_id' => array(
'description' => __( 'Product ID.', 'woocommerce-rest-api' ),
'type' => array( 'integer' ),
'type' => 'mixed',
'context' => array( 'view', 'edit' ),
),
'variation_id' => array(
Expand Down Expand Up @@ -1282,7 +1282,7 @@ public function get_item_schema() {
),
'value' => array(
'description' => __( 'Meta value.', 'woocommerce-rest-api' ),
'type' => array( 'string', 'null' ),
'type' => 'mixed',
'context' => array( 'view', 'edit' ),
),
),
Expand Down Expand Up @@ -1373,7 +1373,7 @@ public function get_item_schema() {
),
'value' => array(
'description' => __( 'Meta value.', 'woocommerce-rest-api' ),
'type' => array( 'string', 'null' ),
'type' => 'mixed',
'context' => array( 'view', 'edit' ),
),
),
Expand All @@ -1397,12 +1397,12 @@ public function get_item_schema() {
),
'method_title' => array(
'description' => __( 'Shipping method name.', 'woocommerce-rest-api' ),
'type' => array( 'string', 'null' ),
'type' => 'mixed',
'context' => array( 'view', 'edit' ),
),
'method_id' => array(
'description' => __( 'Shipping method ID.', 'woocommerce-rest-api' ),
'type' => array( 'string', 'null' ),
'type' => 'mixed',
'context' => array( 'view', 'edit' ),
),
'instance_id' => array(
Expand Down Expand Up @@ -1464,7 +1464,7 @@ public function get_item_schema() {
),
'value' => array(
'description' => __( 'Meta value.', 'woocommerce-rest-api' ),
'type' => array( 'string', 'null' ),
'type' => 'mixed',
'context' => array( 'view', 'edit' ),
),
),
Expand All @@ -1488,7 +1488,7 @@ public function get_item_schema() {
),
'name' => array(
'description' => __( 'Fee name.', 'woocommerce-rest-api' ),
'type' => array( 'string', 'null' ),
'type' => 'mixed',
'context' => array( 'view', 'edit' ),
),
'tax_class' => array(
Expand Down Expand Up @@ -1562,7 +1562,7 @@ public function get_item_schema() {
),
'value' => array(
'description' => __( 'Meta value.', 'woocommerce-rest-api' ),
'type' => array( 'string', 'null' ),
'type' => 'mixed',
'context' => array( 'view', 'edit' ),
),
),
Expand All @@ -1586,7 +1586,7 @@ public function get_item_schema() {
),
'code' => array(
'description' => __( 'Coupon code.', 'woocommerce-rest-api' ),
'type' => array( 'string', 'null' ),
'type' => 'mixed',
'context' => array( 'view', 'edit' ),
),
'discount' => array(
Expand Down Expand Up @@ -1620,7 +1620,7 @@ public function get_item_schema() {
),
'value' => array(
'description' => __( 'Meta value.', 'woocommerce-rest-api' ),
'type' => array( 'string', 'null' ),
'type' => 'mixed',
'context' => array( 'view', 'edit' ),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ public function get_item_schema() {
),
'manage_stock' => array(
'description' => __( 'Stock management at variation level.', 'woocommerce-rest-api' ),
'type' => array( 'boolean', 'null' ),
'type' => 'mixed',
'default' => false,
'context' => array( 'view', 'edit' ),
),
Expand Down Expand Up @@ -980,7 +980,7 @@ public function get_item_schema() {
),
'value' => array(
'description' => __( 'Meta value.', 'woocommerce-rest-api' ),
'type' => array( 'string', 'null' ),
'type' => 'mixed',
'context' => array( 'view', 'edit' ),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2084,7 +2084,7 @@ public function get_item_schema() {
),
'value' => array(
'description' => __( 'Meta value.', 'woocommerce-rest-api' ),
'type' => array( 'string', 'null' ),
'type' => 'mixed',
'context' => array( 'view', 'edit' ),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,18 +530,12 @@ public function get_item_schema() {
),
'value' => array(
'description' => __( 'Setting value.', 'woocommerce-rest-api' ),
'type' => array( 'string', 'array', 'null' ),
'items' => array(
'type' => array( 'string', 'null' ),
),
'type' => 'mixed',
'context' => array( 'view', 'edit' ),
),
'default' => array(
'description' => __( 'Default value for the setting.', 'woocommerce-rest-api' ),
'type' => array( 'string', 'array', 'null' ),
'items' => array(
'type' => array( 'string', 'null' ),
),
'type' => 'mixed',
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
Expand Down
49 changes: 45 additions & 4 deletions src/Controllers/Version3/class-wc-rest-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,57 @@ public function get_endpoint_args_for_item_schema( $method = WP_REST_Server::CRE
return $endpoint_args;
}

$endpoint_args = $this->adjust_wp_5_5_datatype_compatibility( $endpoint_args );

return $endpoint_args;
}

/**
* Change datatypes `date-time` to string, and `mixed` to composite of all built in types. This is required for maintaining forward compatibility with WP 5.5 since custom post types are not supported anymore.
*
* See @link https://core.trac.wordpress.org/changeset/48306
*
* We still use the 'mixed' type, since if we convert to composite type everywhere, it won't work in 5.4 anymore because they require to define the full schema.
*
* @param array $endpoint_args Schema with datatypes to convert.

* @return mixed Schema with converted datatype.
*/
protected function adjust_wp_5_5_datatype_compatibility( $endpoint_args ) {
if ( version_compare( get_bloginfo( 'version' ), '5.5', '<' ) ) {
return $endpoint_args;
}

foreach ( $endpoint_args as $field_id => $params ) {

if ( ! isset( $params['type'] ) ) {
continue;
}

/**
* Custom types are not supported as of WP 5.5, this translates type => 'date-time' to type => 'string' with format date-time.
* Custom types are not supported as of WP 5.5, this translates type => 'date-time' to type => 'string'.
*/
if ( 'date-time' === $params['type'] ) {
$endpoint_args[ $field_id ]['type'] = 'string';
$endpoint_args[ $field_id ]['format'] = 'date-time';
$params['type'] = array( 'null', 'string' );
}

/**
* WARNING: Order of fields here is important, types of fields are ordered from most specific to least specific as perceived by core's built-in type validation methods.
*/
if ( 'mixed' === $params['type'] ) {
$params['type'] = array( 'null', 'object', 'string', 'number', 'boolean', 'integer', 'array' );
}

if ( isset( $params['properties'] ) ) {
$params['properties'] = $this->adjust_wp_5_5_datatype_compatibility( $params['properties'] );
}
}

if ( isset( $params['items'] ) && isset( $params['items']['properties'] ) ) {
$params['items']['properties'] = $this->adjust_wp_5_5_datatype_compatibility( $params['items']['properties'] );
}

$endpoint_args[ $field_id ] = $params;
}
return $endpoint_args;
}

Expand Down
2 changes: 0 additions & 2 deletions src/Controllers/Version3/class-wc-rest-crud-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ public function delete_item_permissions_check( $request ) {
return true;
}



/**
* Get object permalink.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ public function get_item_schema() {
),
'value' => array(
'description' => __( 'Meta value.', 'woocommerce-rest-api' ),
'type' => array( 'string', 'null' ),
'type' => 'mixed',
'context' => array( 'view', 'edit' ),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ public function get_item_schema() {
),
'value' => array(
'description' => __( 'Meta value.', 'woocommerce-rest-api' ),
'type' => array( 'string', 'null' ),
'type' => 'mixed',
'context' => array( 'view', 'edit' ),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,7 @@ public function get_item_schema() {
),
'value' => array(
'description' => __( 'Meta value.', 'woocommerce-rest-api' ),
'type' => array( 'string', 'null' ),
'type' => 'mixed',
'context' => array( 'view', 'edit' ),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,18 +199,12 @@ public function get_item_schema() {
),
'value' => array(
'description' => __( 'Setting value.', 'woocommerce-rest-api' ),
'type' => array( 'string', 'array', 'null' ),
'items' => array(
'type' => array( 'string', 'null' ),
),
'type' => 'mixed',
'context' => array( 'view', 'edit' ),
),
'default' => array(
'description' => __( 'Default value for the setting.', 'woocommerce-rest-api' ),
'type' => array( 'string', 'array', 'null' ),
'items' => array(
'type' => array( 'string', 'null' ),
),
'type' => 'mixed',
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
Expand Down
3 changes: 3 additions & 0 deletions unit-tests/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ protected function load_framework() {
require_once $this->tests_dir . '/Helpers/SettingsHelper.php';
require_once $this->tests_dir . '/Helpers/QueueHelper.php';
require_once $this->tests_dir . '/AbstractRestApiTest.php';

// Traits.
require_once $this->tests_dir . '/traits/trait-wc-rest-api-complex-meta.php';
}
}

Expand Down
14 changes: 14 additions & 0 deletions unit-tests/Tests/Version2/product-variations.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

class Product_Variations_API_V2 extends WC_REST_Unit_Test_Case {
use WC_REST_API_Complex_Meta;

/**
* Setup our test server, endpoints, and user info.
Expand Down Expand Up @@ -299,6 +300,19 @@ public function test_create_variation() {
$this->assertEquals( 3, count( $variations ) );
}

/**
* Test updating complex meta object.
*/
public function test_update_complex_meta_27282() {
wp_set_current_user( $this->user );
$product = \Automattic\WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product();
$product->save();
$variations = $product->get_available_variations( 'objects' );
$first_variation_id = $variations[0]->get_id();
$url = '/wc/v2/products/' . $product->get_id() . '/variations/' . $first_variation_id;
$this->assert_update_complex_meta( $url );
}

/**
* Test creating a single variation without permission.
*
Expand Down
8 changes: 4 additions & 4 deletions unit-tests/Tests/Version2/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -546,10 +546,10 @@ public function test_email_settings() {
array(
'id' => 'subject',
'label' => 'Subject',
'description' => 'Available placeholders: <code>{site_title}</code>, <code>{site_address}</code>, <code>{order_date}</code>, <code>{order_number}</code>',
'description' => 'Available placeholders: <code>{site_title}</code>, <code>{site_address}</code>, <code>{site_url}</code>, <code>{order_date}</code>, <code>{order_number}</code>',
'type' => 'text',
'default' => '',
'tip' => 'Available placeholders: <code>{site_title}</code>, <code>{site_address}</code>, <code>{order_date}</code>, <code>{order_number}</code>',
'tip' => 'Available placeholders: <code>{site_title}</code>, <code>{site_address}</code>, <code>{site_url}</code>, <code>{order_date}</code>, <code>{order_number}</code>',
'value' => '',
),
$setting
Expand All @@ -569,10 +569,10 @@ public function test_email_settings() {
array(
'id' => 'subject',
'label' => 'Subject',
'description' => 'Available placeholders: <code>{site_title}</code>, <code>{site_address}</code>, <code>{order_date}</code>, <code>{order_number}</code>',
'description' => 'Available placeholders: <code>{site_title}</code>, <code>{site_address}</code>, <code>{site_url}</code>, <code>{order_date}</code>, <code>{order_number}</code>',
'type' => 'text',
'default' => '',
'tip' => 'Available placeholders: <code>{site_title}</code>, <code>{site_address}</code>, <code>{order_date}</code>, <code>{order_number}</code>',
'tip' => 'Available placeholders: <code>{site_title}</code>, <code>{site_address}</code>, <code>{site_url}</code>, <code>{order_date}</code>, <code>{order_number}</code>',
'value' => 'This is my subject',
),
$setting
Expand Down
Loading