Woocommerce/WordPress Update Transient Values for Layered Navigation

I am writing an addon for the WooCommerce plugin for WordPress that allows product imports from an excel spreadsheet. All the products import just fine, but I am having trouble updating the layered navigation in the store sidebar. Each item has a manufacturer assigned to it on import and the manufacturer attribute is being set just fine. However, the layered navigation is not being updated – in fact it doesn’t even show up unless I manually update an item.

After doing some digging, it looks like the layered navigation uses an option from wp_options called _transient_wc_ln_count_(hash) to store the count/ids of the items with that attribute. I think this is what I need for my script to work properly, but I can’t find any documentation/examples about it. I’m hoping there is just a function that I can call to update the transient options. Can someone point me in the right direction?

Related posts

Leave a Reply

2 comments

  1. So I never figured out the exact answer to this question, but I found something that works. After using wp_insert_post to initially add the post, and then inserting the post meta (including the manufacturer meta) with the resulting post ID, I am calling the wp_update_post function which triggers all the automatic update functions for that item, including the transient count issue. Now my product manufacturer count in the sidebar is correct. Hope this helps someone else!