Posts

Showing posts with the label setter

Using Product CRUD setter methods in Woocommerce 3

Using Product CRUD setter methods in Woocommerce 3 In the code bellow, I can't set some product category and product tags: The code is located in my functions.php file: <?php $product = new WC_Product; $product->set_name("product"); $product->set_regular_price('150'); $set_cat = $product->set_category_ids( array(17) ); $set_tag = $product->set_tag_ids( [18, 19] ); $product->save(); var_dump($set_cat);//NULL var_dump($set_tag);//NULL The product is created with the correct name and price . But I get nothing for the product category and product tags: name price terms: [terms table][1] term_taxonomy: [term_taxonomy table][2] Edit: I have moved this code in index.php file and It works. index.php Could you add a bit more clarification to this question, what exactly are you trying to do and what aspect of it is not working, have you tried anything else to address the issue? – David Rogers ...