I have comma separated string with attribute values. For example
- Attributes
- Color- Red
- Type - Shockproof, Fashion, third value,
Products are imported from thirdparty software. Also are attributes etc.
Everything is importing fine as there is only one attribute value like Color- Red. When there is more attribute values, then on product edit page in attribute section shows only last value. In this case third value.
My code is here:
foreach ($my_product_attributes as $key => $value) {
$key = 'pa_' . $key;
$commas = substr_count($value, ",");
if($commas >= 1){
$attribute_values = explode(",", $value);
foreach($attribute_values as $attribute){
wp_set_object_terms($p_id, $attribute, $key, false);
$thedata[sanitize_title($key)] = Array(
'name' => wc_clean($key),
'value' => $attribute,
'postion' => '0',
'is_visible' => '1',
'is_variation' => '0',
'is_taxonomy' => '1'
);
update_post_meta($p_id, '_product_attributes', $thedata);
}
}
I know core problem of my code, but i dont know where to fix it, and how