I need to have dynamically created meta fields for WooCommerce product category. Almost everything works, just one thing leave to solve for me. I need to get dynamic $count variable from php and use it into javascript file. For this I am trying use wp_localize_script. Below is my function to enqueue scripts where I need to use $count variable.

This would also help protect against other plugins (or themes) which might add fields with similar naming constructs providing incorrect counts.

In most circumstances you need to update count as well in JS as things are added/removed. By doing the same query, you will get the updated count, or you can increment/decrement based on an action (like click).

Thank you for your help! I went to that direction and my troubles are solved. But just out of curiosity, do you know a solution how to achieve this using PHP? I learn coding and this knowledge can be helpful for me in the future.
– Artus2000Feb 14 at 10:21