I had the same problem, but with image swatches. I don’t think it’s possible with the WooCommerce API only to update all that is needed since you have to mess about with “term_meta” and term_taxonomies and etc. After wrestling with authentication difficulties using the wordpress REST API, I decided to go with old-faithful xmlrpc. This code could be re-written as a plugin (my plan) but for now it can just be put up on your server somewhere. I call this code from our custom db solution via CURL. It’s rough, but, might give anyone else wondering about this a starting point. It requires multiple calls to retrieve, delete/update/add those parts of the term_meta that can’t be set via the WooCommerce API. WordPress xmlrpc documentation is your friend.
<?
if(empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == "off"){ echo "ur doin it wrong https is better"; exit(); }
$protocol='https://';
$username=$_POST['username'];
$password=$_POST['password'];
$blogid=1; //Post ID
$xmlrpcurl=$protocol.'URL-TO-YOUR-BLOG.com/xmlrpc.php';
if($_POST['filename'] && $_POST['action']=="wp.uploadFile"){
$item=$_POST['filename'];
$prefix=$_POST['prefix'];
$file=file_get_contents('https://URL-TO-YOUR-IMAGES.com/'.$filename.'.jpg');
$filetype = "image/jpeg";
$filename = $filename.".jpg";
xmlrpc_set_type($file,'base64'); // <-- required!
$params = array($blogid,$username,$password,
array('name'=>$filename,'type'=>$filetype,'bits'=>$file,'overwrite'=>false));
$request = xmlrpc_encode_request('wp.uploadFile',$params);
}elseif($_POST['postid'] && $_POST['action']=="wp.deletePost"){
$postid=$_POST['postid'];
$params = array($blogid,$username,$password, $postid);
$request = xmlrpc_encode_request('wp.deletePost',$params);
}elseif($_POST['termid'] && $_POST['action']=="wp.editTerm"){
$taxonomy=$_POST['taxonomy'];
$termid=$_POST['termid'];
$meta[]=array('key'=>$_POST['key'],'value'=>$_POST['value']);
$metaParam=array('custom_fields'=>$meta, 'taxonomy'=>$taxonomy);
$params = array($blogid,$username,$password, $termid,$metaParam);
$request = xmlrpc_encode_request('wp.editTerm',$params);
}elseif($_POST['taxonomy'] && $_POST['action']=="wp.getTerms"){
$taxonomy=$_POST['taxonomy'];
$params = array($blogid,$username,$password,$taxonomy);
$request = xmlrpc_encode_request('wp.getTerms',$params);
}elseif($_POST['taxonomy'] && $_POST['termid'] && $_POST['action']=="wp.deleteTerm"){
$termid=$_POST['termid'];
$taxonomy=$_POST['taxonomy'];
$params = array($blogid,$username,$password,$taxonomy, $termid);
$request = xmlrpc_encode_request('wp.deleteTerm',$params);
}else{
echo '{"error":"no requests"}';
}
if($request){
$result = go($request,$xmlrpcurl);
$json_result = json_encode($result);
echo $json_result;
}else{
echo '{"error":"no data"}';
}
function go($request,$xmlrpcurl){
$ch = curl_init();
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_URL,$xmlrpcurl);
curl_setopt($ch,CURLOPT_POSTFIELDS,$request );
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$result = curl_exec($ch);
if($result){
return xmlrpc_decode($result);
}else{
echo '{"error":"no url or data encoded"}';
}
}