Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange behaviour when using wpinv_get_item_price filter hook. Possible bug? #809

Open
aayla-secura opened this issue Oct 12, 2024 · 1 comment

Comments

@aayla-secura
Copy link

aayla-secura commented Oct 12, 2024

Not 100% if it's a bug or I'm doing it wrong.

Am I correct that if a developer wants to programmatically and dynamically change how much a user is charged for an item, they should add a filter hook for wpinv_get_item_price? As in:

add_filter(
    'wpinv_get_item_price',
    function ($price, $item) {
        return 50; // or whatever, dynamic based on other conditions
    },
    10,
    2
);

I'm doing this and seeing some strange behaviour.

  1. Firstly, when I change the price using this filter hook to 0, to make the item free for some users, checkout fails with a vague error: "An error occured while processing your payment. Please try again." and nothing more is logger either.

  2. Secondly, when I change the price to something above 0, even though the user is charged the custom amount I return from the filter hook, at least according to Stripe, the total amount of the invoice reflects the original price, which is confusing:

Screenshot 2024-10-12 203825

  1. The third peculiarity, is that when I return a custom price from that filter hook, the user-set/dynamic pricing during checkout no longer works. The price that the user inputs always gets overridden with what I return from the hook. If I just return the original price from the hook, it works again...

What is the correct way to set dynamic pricing server-side (i.e. not using "let customer name their price")? And how is the wpinv_get_item_price supposed to be used?

@aayla-secura
Copy link
Author

Well, I found a way to set an item price during checkout: using the filter hook getpaid_payment_form_submission_processed_item and editing the form item's price there works as expected.

But I'll leave this open as I wonder whether the wpinv_get_item_price should also have the same effect, or if not, what is its intended use case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant