I've inserted the attribute manually after inserting new products through code:
$attributes = Array(
"type_product1" => $data1,
"type_product2" => $data2,
"type_product3" => $data3,
"type_product4" => $data4,
"type_product5" => $data5,
"type_product6" => $data5
);
foreach ($attributes as $key => $value) {
$term_taxonomy_ids = wp_set_object_terms( $product_id, $value, 'pa_'.$key, true );
$product_attributes = Array (
'pa_'.$key => Array(
'name' => 'pa_'.$key, // set attribute name
'value' => $value, // set attribute value
'is_visible' => 1,
'is_variation' => '1',
'is_taxonomy' => 1
)
);
}
//Add as post meta
update_post_meta($post_ID, '_product_attributes', $product_attributes);
after that if I go in products -> attribute i see the count of single terms of name of attributes incremented but if i go in the single product under name attributes (custom product attribute) i'll see only last attribute (type_product6) set with value other attributes are not shown.... The strange thing is that if I go to the attribute page and i click on the count of single term of attribute it shows me the list of product with this attribute set!
How can I fix it?
I've inserted the attribute manually after inserting new products through code:
$attributes = Array(
"type_product1" => $data1,
"type_product2" => $data2,
"type_product3" => $data3,
"type_product4" => $data4,
"type_product5" => $data5,
"type_product6" => $data5
);
foreach ($attributes as $key => $value) {
$term_taxonomy_ids = wp_set_object_terms( $product_id, $value, 'pa_'.$key, true );
$product_attributes = Array (
'pa_'.$key => Array(
'name' => 'pa_'.$key, // set attribute name
'value' => $value, // set attribute value
'is_visible' => 1,
'is_variation' => '1',
'is_taxonomy' => 1
)
);
}
//Add as post meta
update_post_meta($post_ID, '_product_attributes', $product_attributes);
after that if I go in products -> attribute i see the count of single terms of name of attributes incremented but if i go in the single product under name attributes (custom product attribute) i'll see only last attribute (type_product6) set with value other attributes are not shown.... The strange thing is that if I go to the attribute page and i click on the count of single term of attribute it shows me the list of product with this attribute set!
How can I fix it?
Share Improve this question edited Jun 15, 2017 at 15:43 walle asked Jun 1, 2017 at 9:45 wallewalle 132 silver badges7 bronze badges 1- Does anyone have an idea? – walle Commented Jun 15, 2017 at 13:13
1 Answer
Reset to default 1the solution is:
foreach ($attributes as $attr => $value) {
$attr = 'pa_'.$attr;
wp_set_object_terms($post_ID, $value, $attr);
$thedata[sanitize_title($attr)] = Array(
'name' => wc_clean($attr),
'value' => $value,
'postion' => '0',
'is_visible' => '1',
'is_variation' => '1',
'is_taxonomy' => '1'
);
}
update_post_meta($post_ID, '_product_attributes', $thedata);
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745176578a4615221.html
评论列表(0条)