我想以编程方式设置一些产品类别。当一个新产品发布时,它正在工作。但当我可以更新它时,它会显示一个错误,如:后端致命错误:PHP致命错误:无法在插件/自定义同步产品/trade\\u函数中使用WP\\u error类型的对象作为数组。php第100行\\n.任何人都可以帮助我解决此错误。
function set_product_category_woo($T_product_type,$post_id){
$product_categories = term_exists($T_product_type,"product_cat");
if(empty($product_categories)){
$slug=str_replace(" ","_",$T_product_type);
$resp=wp_insert_term($T_product_type,\'product_cat\',array(\'description\'=> \'\',\'slug\' =>$slug));
/****assign category to the product in woo***/
if(isset($resp)){
wp_set_object_terms($post_id,$resp[\'term_id\'], \'product_cat\' );
}else{
file_put_contents("text.txt","\\n".print_r($resp),FILE_APPEND);
}