Skip to content
Advertisement

Woocommerce: function to update all products

I have an issue with my Woocommerce products. This issue is fixed if I just update the product (edit the product and click in the Update button) with no changes at all.

I have around 2000 products in my site, then I am thinking of doing this using a function in my function.php file.

It should be something like this, I just need the line which update the product.

JavaScript

Advertisement

Answer

Try the following, that will update your products by 200 each time to avoid problems (if you have variable products also, the post_type arg will need to be product & product_variation):

JavaScript

Code goes in function.php file of your active child theme (or active theme). Tested and works.

Each time you will browse a page of your site the function will be triggered. processing products by 200 is just more secure and will avoid a timeout or errors.

You can increase that number to 500 for example, setting the $limit to 500

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement