Shopify Function Validation Failing After Logout Due to Cart Re-add Issue

I’m facing an issue with a Shopify function we’re using for cart and checkout validation, which checks if a customer has a specific tag before allowing them to purchase certain products. The problem arises when a customer logs out: Shopify automatically removes the items from the cart and then re-adds them after the logout process is complete. Since the customer is now logged out, they no longer have the necessary tag, causing the validation to fail during this re-add process and preventing the logout from completing successfully.

My questions are:

  1. Has anyone else encountered a similar issue with cart re-add after logout causing validation failures?
  2. Is there a way to identify in the Shopify function for cart and checkout validation whether the input is coming from this automatic re-add triggered by logout? If I can identify these re-adds, I could bypass them to ensure the logout function works as expected.

For more details, I’ve attached a screen recording of the issue: Video Link.

Any advice or suggestions would be greatly appreciated!

Thanks!