add_post_meta add latest data from meta_value array
Question
I want to add list of color to a product attribute with following code:
function wcproduct_set_attributes($post_id, $_attributes) {
$i = 0;
foreach ($_attributes as $name => $value) {
wp_set_object_terms($post_id, $value, $name);
$product_attributes[$i] = array (
'name' => $name, // set attribute name
'value' => $value, // set attribute value
'is_visible' => 0,
'is_variation' => 1,
'is_taxonomy' => 1
);
}
$i++;
update_post_meta($post_id, '_product_attributes', $product_attributes);
};
wcproduct_set_attributes($_product_id_data, $my_product_attributes);
$product_attributes is an array of colors and $name is pa_color and $value is color name. this function works but it add last color to pa_color.
0
array, woocommerce
3 years
2020-06-01T04:10:41-05:00
2020-06-01T04:10:41-05:00 0 Answers
92 views
0
Leave an answer