Products - date created is read only via the API, but updatable within admin #104
Comments
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); |
Solved in woocommerce/woocommerce#21117 |
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? |
@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. |
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). |
Comes inside |
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? |
@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',
]
); |
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
The text was updated successfully, but these errors were encountered: