0

I am trying to add an attribute to some products in Woocommerce. I am able to do so, using the following :

wp_set_object_terms( $product_id, 'Test Model #', 'pa_model' , false);

Cool. The data stores into the product. Now when I view the product on the front end, nothing appears in the additional data tab. The tab is there but no data exists inside the tab.

If I edit the post, the product attributes exist on the product, but are not displaying on the front end.

If I hit Update Post, the data then appears on the front end. But does not until I hit update, which isn't ideal in situations where I need to update hundreds of products at a time.

Is there something I'm missing after wp_set_object_terms to store the data properly?

Screenshots to help illustrate what I'm referring too :

Backend Product Attributes Immediatly following an Import: https://i.cloudup.com/KQA2L1rPCI.png

This is the front end display : https://cloudup.com/iiyxQqKx8G8

And the front end display AFTER i re-save the imported product : https://cloudup.com/c9UGI-z43UP

closed as off-topic by Rarst Dec 3 '14 at 17:48

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

1

According to The Codex on wp_set_object_terms() get set by passing in a slug instead of the actual Term Name:

wp_set_object_terms( $object_id, $terms, $taxonomy, $append );

$terms

(array/int/string) (required) The slug or id of the term (such as category or tag IDs), will replace all existing related terms in this taxonomy. To clear or remove all terms from an object, pass an empty string or NULL. Integers are interpreted as tag IDs.

This may work for you ( not sure if WP slugs strip # or not so this slug is just a guess ).

wp_set_object_terms( $product_id, 'test-model-#', 'pa_model' , false);

  • The data appears to be saving, as I can see it in the backend product attribute section but on the front end nothing displays until I re-save the post. Backend : i.cloudup.com/KQA2L1rPCI.png Front end display :cloudup.com/iiyxQqKx8G8 – EHerman Dec 3 '14 at 16:18
  • This may be WooCommerce specific then. I know Woo handles attributes a little bit differently than default. You're better off asking experts in the WooCommerce Community or The WooCommerce WP Forums. You may need to do extra things so that WooCommerce recognizes it as actual Woo data. – Howdy_McGee Dec 3 '14 at 16:26

Not the answer you're looking for? Browse other questions tagged or ask your own question.