We have a Woocommerce website with over 1000 products on.
Is it possible to set a default attribute term for every product.
The attribute name is ‘pa_arm-length’ and the term is ‘1’.
So for example every single product would need an attribute enabled with a term of ‘1’;
is this possible without having to go into every product individually, enable attribute and then assign it a term?
I can do it like this but it only works if the attribute already has a term assigned
wp_set_object_terms( $object_id, '1', 'pa_arm-length' , true);
Thanks in advance.
2
Answers
Ok so i have an update if this is helpful to anyone else.
The following need to be run inside the product loop.
For it to work i needed to include the existing attribute sets in the array (colour and size). That way it doesn't get overwritten when you run update_post_meta().
i think this is what your looking for. this should add the pa_arm-length to every product with value 1. let me know if this works for you. you can also check this link for more details