I have a form to submit new books to my WooCommerce website. I used to have it just save the book's condition as a Product Attribute.
// Set the book's condition
$condition = $_POST['condition'];
wp_set_object_terms( $product_id, $condition, 'pa_condition', true );
$att_condition = Array('pa_condition' =>Array(
'name'=>'pa_condition',
'value'=>$condition,
'is_visible' => '1',
'is_taxonomy' => '1'
));
update_post_meta( $product_id, '_product_attributes', $att_condition);
That was easy. Now I am trying to add the Book Author's name and the Genre, but when I duplicated the code it only sets the last Product Attribute. I know I should probably put it in a loop, but I'm being stupid and otherwise I can't figure out what I am missing.
$condition = $_POST['condition'];
$genre = $_POST['genre'];
$author = $_POST['author'];
wp_set_object_terms( $product_id, $condition, 'pa_condition', true );
$att_condition = Array('pa_condition' =>Array(
'name'=>'pa_condition',
'value'=>$condition,
'is_visible' => '1',
'is_taxonomy' => '1'
));
update_post_meta( $product_id, '_product_attributes', $att_condition);
wp_set_object_terms( $product_id, $genre, 'pa_genre', true );
$att_condition = Array('pa_genre' =>Array(
'name'=>'pa_genre',
'value'=>$genre,
'is_visible' => '1',
'is_taxonomy' => '1'
));
update_post_meta( $product_id, '_product_attributes', $att_genre);
wp_set_object_terms( $product_id, $author, 'pa_author', true );
$att_author = Array('pa_author' =>Array(
'name'=>'pa_author',
'value'=>$author,
'is_visible' => '1',
'is_taxonomy' => '1'
));
update_post_meta( $product_id, '_product_attributes', $att_author);