我使用以下代码向产品添加属性:
foreach ($_attributes as $name => $value) {
wp_set_object_terms($post_id, $value, $name, true);
$product_attributes[$name] = array (
'name' => $name, // set attribute name
'value' => $value, // set attribute value
'is_visible' => 0,
'is_variation' => 1,
'is_taxonomy' => 1
);
}
update_post_meta($post_id, '_product_attributes', $product_attributes );
但会删除我在admin中的产品编辑中添加的先前属性,例如产品品牌或型号。如何在不删除先前属性的情况下更新当前产品属性?
谢谢帮助我。
您可以在更新之前简单地备份数据库内容,如下所示:
$tmpBk = get_post_meta($post_id, '_product_attributes',true);
update_post_meta($post_id, '_product_attributes', array_merge(tmpBk,$product_attributes) );
应该足以保存您以前存储的值
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句