Skip to content
Advertisement

How do I set custom product meta on a new product using WooCommerce Core?

I’m adding new products (car listings) to my WooCommerce shop in bulk in PHP. I’m looping through rows in a custom data table and adding them as WooCommerce products.

I’m able to save each product and add the default meta (ie. description, price, sku, visibility, etc). However, I am not able to set custom product meta. Am I doing this in the wrong order?

Below is the code in my FOREACH loop that saves each row (but the “set_meta_data” is not working).

JavaScript

Advertisement

Answer

set_meta_data method require another piece of meta structure (with id).

I think is better use update_meta_data method in loop:

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