Skip to content

Conversation

@jeffstieler
Copy link
Contributor

@jeffstieler jeffstieler commented Oct 5, 2021

All Submissions:

Changes proposed in this Pull Request:

Closes #25255.

This PR adds logic to alter the Variable Product price hash (cache key) when the current customer is VAT exempt.

How to test the changes in this Pull Request:

(Lovingly plagiarized from the issue)

  1. Setup a variable product with taxes
  2. Set prices in the store to show including taxes
  3. Set up taxes for the site, it's the easiest to reproduce with just one tax rate for every location
  4. Use one logged in user and save a location as well as a matching VAT number in their account
  5. View the shop page and you should now see the variable product with no tax (user is tax exempt)
  6. In an incognito window view the same shop page and verify that the variable product is shown with taxes
  7. Clear the transients in WooCommerce > Status > Tools
  8. Refresh the incognito window and see the variable product including taxes
  9. Now refresh the shop page again for the logged in user and verify the variable product still shows without taxes

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • [x Have you successfully run tests with your changes locally?

Changelog entry

Fix - Variable product price caching bug with VAT exemption.

FOR PR REVIEWER ONLY:

  • I have reviewed that everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities. I made sure Linting is not ignored or disabled.

@jeffstieler jeffstieler added Bug The issue is a confirmed bug. priority: high labels Oct 5, 2021
@vedanshujain vedanshujain requested review from a team and barryhughes and removed request for a team October 7, 2021 12:33
Copy link
Member

@barryhughes barryhughes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Code looks good, works as per test instructions.

@barryhughes barryhughes merged commit 942d6c8 into trunk Oct 7, 2021
@barryhughes barryhughes deleted the fix/25255-variable-product-price-hash branch October 7, 2021 23:28
@github-actions github-actions bot added this to the 5.9.0 milestone Oct 7, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Oct 7, 2021

Hi @barryhughes, thanks for merging this pull request. Please take a look at these follow-up tasks you may need to perform:

  • Add the status: needs changelog label
  • Add the status: needs testing instructions label

@barryhughes barryhughes added release: add changelog Mark all PRs that have not had their changelog entries added. [auto] release: add testing instructions PRs that have not had testing instructions added to the wiki. [auto] labels Oct 7, 2021
@Konamiman Konamiman added changelog added and removed release: add changelog Mark all PRs that have not had their changelog entries added. [auto] labels Oct 15, 2021
@tammullen tammullen added testing instructions added and removed release: add testing instructions PRs that have not had testing instructions added to the wiki. [auto] labels Oct 20, 2021
@masahrpro
Copy link

Hi guys! I am thos one posting the original issue.

We now found another scenario that triggers this problem with the transients displaying prices without VAT.
We tried to apply the fix given here by @vedanshujain , but unfortunately it does not work as desired in our scenario.

Our client has a store that uses user roles to display discounted prices for wholesale/retailers. Once a retailer logs in, immediately the cross-out prices and the discounted price shows without VAT, even all the settings are set to include VAT.

What makes it worse, once the prices are saved in the transients, any clients regardless of the user role are now able to see and checkout with the VAT0% pricing that creates a huge loss of profits.

Clearing the transients fixes the issue temporarily once incorrect prices are discovered, but this requires a huge amount of manual work and constantly monitoring the store for the bug to happen.

Due to client confidentiality I am not able to share the link here publicly, but if you need, we have a staging version of the site available for troubleshooting/ testing. Just let me know how to share those with you in private.

@jeffstieler
Copy link
Contributor Author

Hi @masahrpro,

Since the user role isn't used by core WooCommerce in pricing, I think the solution should be to use the woocommerce_get_variation_prices_hash filter to add the user's role to the price hash.

If you are using an extension from our marketplace for role based pricing, let us know so we can surface the issue to the developers.

@masahrpro
Copy link

Thanks for the tip @jeffstieler ! We will try that.
We are using the "https://www.role-editor.com/" and I have also contacted them regarding this.
Although, even users not affected by the user role editor- plugin are affected, as the incorrect prices are saved in the transients and require to be cleared to fix the display of the prices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug The issue is a confirmed bug.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Variable product prices are cached with the wrong tax amount

6 participants