I implemented a custom dynamic data tag that returns the number of items in a Woo Commerce cart. While the tag works well in the page content, it is not functioning as expected with creating conditions for a block – eg. to hide a block when the cart count is “0”
I’ve tried returning a number of different values to test, using different conditions – empty, ==, >=, both text and numbers. No matter what I try, the conditions logic does not seem to evaluate the returned value correctly against the condition’s value.
Interestingly, it works fine using something like {post_id} and other built-in DD fields. It also works perfectly if I use an {echo:} to return the value from a custom function. Which is fine for this case, but for simplicity’s sake I would really like it to work with my custom DD field instead.
I might be missing something, but it seems that the conditions logic is not seeing my returned value correctly. Even doing a simple var_dump on the conditions.php logic shows that $value is a string longer than the actual content, and is not comparing it correctly to $required.
Yes, I started with the example in the Academy. The only difference is that I generally put my filter functions in a class and built the function to handle multiple tags instead of just one. All of my tags are rendering correctly in basic text and other places, like urls.
I believe this is NO BUG, but I will wait for your confirmation before I mark the topic as so.
In your code, you are checking for a tag position.
If the tag is in the beginning, the result will be 0, therefore it will be false, and this will not execute.
That is probably why it is not working in a condition, but it’s working in a basic text. If you only add your dynamic tag into the basic text, I am quite sure it will not render, right?
So, try to remove this check or compare it by adding !== false, and it should work.
Let me know if this will solve the problem.
Thanks!
thanks… That was the issue. I changed that to str_contains and that works. It was rendering fine in text but not for the condition. My bad. I spent to much time chasing my tail on that one.