php - How to change post meta for all products on product add in WooCommerce?
674
So I am using woocommerce and am using a plugin called WP-All-Import to import a database of products into my Quickbooks connected e-commerce platform. Now I need to change the meta "_sync_status" to "on" for all products after this is complete. How would I do that for all products as they get added?
Answer
Solution:
You first need to fetch all of the WooCommerce Products (post type of "product"), loop over each of them, and update the post meta for each. You can run this code by placing it in your
functions.php
in your theme, a file in the/wp-content/mu-plugins
"must-use" plugins directory, or anonymously using a plugin like WordPress Developer + Console.Answer
Solution:
Thank you its work for me i can update and add new post meta to my products.
Answer
Solution:
The
pre_post_update
hook is called before the post is saved.If you wish to do this when they get created or updated you can hijack the REQUEST array
If you only want to do this when they 'get added' use: