0

I'm a bit new to Woocomerce plugin and have a problem.

I need to create products from code not from admin page. Probably I will insert them with wp_insert_post( $product ).

The problem is I don't know how to set the category for this product. I know it's name, not the ID (in fact I know ID but it can change). How can I add the product to that category?

1 Answer 1

1

You can use wp_set_object_terms fx

From Codex:

This function relates an object (post, link etc) to a term and taxonomy type (tag, category, etc). Creates the term and taxonomy relationship if it doesn't already exist.

wp_set_object_terms( 'id of product', 'term name', 'product_cat', true );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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