我一直在四处寻找,但没能让它开始工作。
使用api v3,我能够获得所有订单,一切正常,但现在我需要能够更新元数据,当我使用失眠时,我设法更新元数据,但现在我需要从php script中进行更新,但它不能工作。
使用put治疗失眠症。
{ "meta_data":{“meta_data”:"_mensajero","value":"juan“}
它工作并更新订单元,但无论我如何尝试php,我都无法使它更新。
<?php
if (isset($_POST['btn-update'])) {
$oid = $_POST['cId']; /////the order id
$data = [
'meta_data' => [
'_mensajero' => '_mensajero'
]
];
$woocommerce->put('orders/' . $oid, $data);
header('Location: #');
}
?> 发布于 2022-01-26 15:30:48
有多种方法来更新元数据。一种常见的方法是使用order object及其方法之一update_meta_data。如下所示:
if (isset($_POST['btn-update']))
{
$oid = absint($_POST['cId']); // the order id
if($oid)
{
$order = wc_get_order($oid);
if($order)
{
$order->update_meta_data('_mensajero', '_mensajero');
$order->save();
// Do what ever you want here
}else{
die('NO ORDER WITH THE PROVIDED ID FOUND!');
// OR send back a custom error message using 'wp_send_json_error' function
}
}else{
die('NO ORDER ID RECIEVED!');
// OR send back a custom error message using 'wp_send_json_error' function
}
}另一种使用update_post_meta函数更新元数据的方法:
if (isset($_POST['btn-update']))
{
$oid = absint($_POST['cId']); // the order id
if($oid)
{
$order = wc_get_order($oid);
if ($order) {
update_post_meta($oid, '_mensajero', '_mensajero');
// Do what ever you want here
} else {
die('NO ORDER WITH THE PROVIDED ID FOUND!');
// OR send back a custom error message using 'wp_send_json_error' function
}
}else{
die('NO ORDER ID RECIEVED!');
// OR send back a custom error message using 'wp_send_json_error' function
}
}https://stackoverflow.com/questions/70858955
复制相似问题