You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
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:
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?
The text was updated successfully, but these errors were encountered:
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?
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:I'm doing this and seeing some strange behaviour.
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.
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:
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?The text was updated successfully, but these errors were encountered: