Programatically update Custom Attributes WooCommerce

OK so I had a variation of this same problem myself and I’ll walk you through it.

All works fine, except for one thing: WooCommerce custom product attributes are not displayed instantly in dropdown/select filters on the website. However, ‘manually’ pressing Update on the WordPress-page does the job.

When displaying attributes woocommerce does this function: wc_get_attribute_taxonomies() (http://woocommerce.wp-a2z.org/oik_api/wc_get_attribute_taxonomies/)

You’ll notice in that function that it is getting the data from a ‘transient’ (think cached data, see http://codex.wordpress.org/Transients_API).

If you are manually uploading data into the database, chances are, you’ve missed uploading the transient (which goes into wp_options by the way). By hitting update in the WordPress admin panel you run the function which updates the transient which is why they work/show then and not before.

To make this work you need to make sure that your manual updating of the MySQL also updates the transient. For me, manually adding product attributes in woocommerce, I had to add a row in wp_options with options_name _transient_wc_attribute_taxonomies and my attributes in the serialized array in the option_value column (plus an ID autoload set to yes). But there are other transients so it depends on which function is causing the issue and what you are trying to display. You can see which one you are missing by doing a MySQL search for %transient% in wp_options once before you click update in the wordpress admin panel and once after then comparing the data.