php - Wordpress search/create attribute assign then search/add value

Solution:
If you only set the value in post_meta, you cant see the attributes on the edit product screen. Try adding wp_set_object_terms to your foreach
foreach($product->attributes as $attribute) {
$slug = 'pa_' . strtolower($attribute->name);
$attribute_value = $attribute->value;
wp_set_object_terms($post_id, attribute->value, $attribute->name, true);
$thedata = [
$slug => [
'name'=> $slug,
'value'=> $attribute_value,
'is_visible' => '1',
'is_variation' => '1',
'is_taxonomy' => '1'
]
];
update_post_meta( $product_id, '_product_attributes', $thedata);
}
There is a post about it on SO here.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: target class [commandmakecommand] does not exist.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.