admin管理员组文章数量:1415664
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);
本文标签: woocommerce offtopicAdd attribute taxonomy through code don39t appear in admin product page
版权声明:本文标题:woocommerce offtopic - Add attribute taxonomy through code don't appear in admin product page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745176578a2646268.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论