Skip to content
This repository has been archived by the owner on Oct 4, 2019. It is now read-only.

Products - date created is read only via the API, but updatable within admin #104

Closed
mikejolley opened this issue Apr 16, 2018 · 8 comments
Labels
Milestone

Comments

@mikejolley
Copy link
Member

date_created is a read only field but I'm not sure why. Can/should this be made editable in the next version?

Request was here woocommerce/woocommerce#19731

cc @claudiosanches

@callumstrubi
Copy link

callumstrubi commented Apr 16, 2018

This is achievable trivially with the hook:

add_filter("woocommerce_rest_pre_insert_product_object", function($product, $request, $creating){
	if($request['date'] || $request['date_gmt']){
		$date = new \DateTime(($request['date_gmt'] ? $request['date_gmt'] : $request['date']), new \DateTimeZone('UTC'));
		$product->set_date_created($date->format('U'));
	}
	return $product;
}, 10, 3);

@claudiosanches
Copy link
Contributor

claudiosanches commented Sep 12, 2018

Solved in woocommerce/woocommerce#21117

@callumstrubi
Copy link

Ah excellent, didn't see this in the release notes for 3.5 - do we expect this to be compatible with my hook, or do i need to do testing?

@claudiosanches
Copy link
Contributor

@callumstrubi we should write a blog post about REST API v3 in the next weeks. About your hook should still work, but probably you should stop using it in v3.

@callumstrubi
Copy link

API v3 will come with a new endpoint though right? So we can plan migration effectively - thank you for the update and hard work in a v3 (WP limitations are constraining v2 too much).

@claudiosanches
Copy link
Contributor

Comes inside wc/v3 instead of wc/v2, so yes, you can do a migration to all new endpoints, test before and so on.

@callumstrubi
Copy link

Sorry for comment spam - will wc-api-php be upgraded to support the v3 endpoint in line with it's release or will that come in the following months?

@claudiosanches
Copy link
Contributor

@callumstrubi already supports, just set the library to connect to v3.

Example:

require __DIR__ . '/vendor/autoload.php';

use Automattic\WooCommerce\Client;

$woocommerce = new Client(
    'http://example.com', 
    'ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 
    'cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
    [
        'wp_api' => true,
        'version' => 'wc/v3',
    ]
);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants