I have a form to submit new books to my WooCommerce site. I used to just save the book's condition as a product attribute. </p>
// 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);
It's easy. Now I try to add the book author name and genre but when I copy the code it only sets the last product attribute. I know I should probably put it in a loop, but I%
Glad you found a solution. However, the question of the original question has not been answered, and there is a simple bug in your solution that should be improved.
Back to the original question.
There are multiple issues with your original code.
The variable naming and usage in your code contains errors. Adjust %E for the second time
I found the solution on https://stackoverflow.com/a/45475863/12092133.
I put the form variables into an array and then ran this foreach and it worked.