Tips and Tricks HQ Support Portal › Forums › WP eStore Forum › eStore – how to access purchased items ids at thank you page?
- This topic has 12 replies, 3 voices, and was last updated 8 years, 6 months ago by
wzp.
-
AuthorPosts
-
July 22, 2016 at 4:36 am #13612
Olik
MemberHi,
Is it possible to somehow (maybe through Session) to access in the Thank You page (in its php code) the information on which items were purchased? Or at least to which categories they belong?
Maybe it’s possible to configure somewhere, which information is accessible in the Thank You page?
Thank you!
July 22, 2016 at 12:05 pm #73742wzp
ModeratorWhat is the “end result,” of what you want to accomplish?
July 22, 2016 at 7:29 pm #73743Olik
MemberI want to show (on the ‘thank you’ page) a corresponding set of messages – if the purchased item was of downloadable nature, it is one set of messages, if physical – another. Also, if the purchased was subscription or a once-payment, it also will influence the set of messages.
Also, as an upsell, it would be nice to show a set of related items to those purchased.
Thank you!
July 23, 2016 at 3:37 am #73744admin
KeymasterWe have the following filter that you can use to access the Thank you page display info and transaction data:
eStore_tx_result_session_data
Here is an example showing how to use this filter:
add_filter('eStore_tx_result_session_data','custom_tx_output_manipulation', 10, 3);
function custom_tx_output_manipulation($output, $payment_data, $cart_items){
//TODO - you can read data from the payment_data and cart_items array.
//TOOD - manipulate the output according to your needs.
//Whatever you return from here will get shown on the thank you page.
return $output;
}July 23, 2016 at 7:24 am #73745Olik
MemberThank you very much! I will try that!
August 7, 2016 at 8:31 pm #73746Olik
MemberHi,
I now set the Sandbox environment and started to test it. And I saw, that it isn’t working – the filter function doesn’t get called.
I looked through the site documentation, and I found this page:
https://www.tipsandtricks-hq.com/ecommerce/wp-estore-instant-digital-product-delivery-499
Does it mean, it’s the only option I have – I need to do all that in order to get the product ids that were purchased, in my php code, producing Thank You page?
I looked through PayPal’s documentation, and from what I understand, there is no way to set PDT in Sandbox account. So I couldn’t test it.
And I’m thinking.. – I don’t need those shortcodes to work, I don’t need the transaction id, I only need the ids of the items that were purchased (I would extract them myself in PHP, no need for any system output or download links). Surely, even without PDT, eStore plugin sends the emails to the buyer and to the seller, does the membership upgrades etc., so the system still knows, even without all those options, which items were purchased, right?
So maybe, there is a way for me to extract it somehow? Maybe from the database, or however?
Thank you!
P.S. I might have just found another solution! I just saw there is an addon for Post Payment Actions, I will try to extract the needed code from there, and then report, if it gave the solution. Thank you!
August 8, 2016 at 4:14 am #73747admin
KeymasterYou can use the IPN hook if you don’t need the thank you page stuff. I get the feeling you are not very familiar with PDT and IPN (there is a big difference). You should read up on that first so you understand what you really want then you can ask me the right question.
The following is an example of how you can use the hook to do some custom processing AFTER and IPN has been processed.
add_filter('eStore_product_database_updated_after_payment','custom_ipn_processing', 10, 2);
function custom_ipn_processing($payment_data, $cart_items){
//TODO - you can read data from the payment_data and cart_items array.
//TOOD - do the extra stuff here
}August 8, 2016 at 6:01 am #73748Olik
MemberHi,
I will describe to you both the problems and the solution, just in case you might need it some time.
What I need is the following: when constructing the html (in php) for Thank You page, I need to have id’s of those items that were just purchased.
The filter you suggested first, I tried and saw it never got called. I looked at the code and got the idea that it would only be working when PDT is set. But it seems like too much is required for that PDT, plus it cannot be tested with Sandbox.
I don’t really care, if it’s IPN or PDT or anything else, as soon as it’s working, doesn’t have too many requirements (PDT, for example, requires Business account and many settings in different places) and can be tested in Sandbox.
The function you just suggested, – I found it as action, not filter, in that addon for Post Payment Actions.
I copied it from there to my code, and it worked.. kind of.
Why kind of – because sometimes it got called before the Thank You page is shown, and sometimes after!
I’m checking in the eStore_payment_debug log. I see that when I pay (in Sandbox) and return to Thank You page after PayPal, sometimes the data is updated, and sometimes not.
When I check the log, I see that when it is updated – the function called on that action hook, was called before the php code runs that creates Thank You page.
And when the data is not updated – I can see in the payment log that the function from action hook wasn’t called yet. When I refresh the debug log a bit later – it shows the debug info printed in that function from action hook.
When I then refresh (or just load afresh) the Thank You page, the data is shown updated.
I updated the priority of the add_action call, to 1 instead of 10, it helped a bit, but still not always managed to work on time.
Then I went to see, where this action is called, and found, that earlier in that processing there is a filter,
eStore_notification_email_body_filter
, which certainly gets called earlier.So I called it, and it helped.
Since I called it early and
payment_data['eMember_userid']
wasn’t there yet, I parsed theipn_data['custom']
.A big challenge was that the php code, creating Thank You page, and the code that runs on that action or filter, run in different web sessions, so no cookies, no global variables, no session could help.
So what I did was:
(In the action/filter)
From the ipn_data (
$payment_data
) I got eMember_id, got by it WP user id.From the cart_items I got the purchased item id’s.
Then I wrote them into WP user_meta, to that user id.
(In the php code, creating Thank You page)
From member logged in, got eMember_id, got by it WP user id.
Read, used and deleted the user_meta field.
I hope, with that early call (to that filter) it will continue to work.
Thank you for your help, plugins and addons, I learn from them a lot.
August 8, 2016 at 12:53 pm #73749Olik
MemberOk, I give up, it isn’t working as I would expect – sometimes IPN indeed, sends the notification to the site too late, when the Thank You page is already shown.
I read about the difference between IPN and PDT, I found, that I can set PDT for testing with Sandbox, too, I followed both your and PayPal’s instructions on setting PDT, and it isn’t working.
Can you please tell me, where even to begin to debug it?
On this page: https://www.tipsandtricks-hq.com/ecommerce/wp-estore-instant-digital-product-delivery-499 I did all it said, I even put the code
[wp_eStore_display_transaction_result]
(even though in your code it is said that it is deprecated – but I put it just in case it did call some functions that would be needed, and also I thought maybe I could see, how to retrieve the data, coming from PDT) in our Thank You page, and it leaves it all empty.When I check the code of this shortcode function, I understand, that it couldn’t work – because
$_SESSION
doesn’t contain the needed “tx” variables.And the filter function you told me to use, is still never called.
Aside from that, I see that the payment process at the PayPal Sandbox became much longer, when I enabled PDT (and Auto). So it does do something?
Could you please help?
Thank you!
By the way, I just saw this: “currently you need to have auto redirect enabled in your PayPal account for this feature” at the bottom of that article above. What exactly redirect is meant here? I didn’t find any redirect feature there, except for Auto Return. Is it what is meant?
Thank you!
August 8, 2016 at 1:50 pm #73750wzp
Moderator…sometimes IPN indeed, sends the notification to the site too late, when the Thank You page is already shown.
Sometimes, the delay may be caused by the kind of hosting package you are using:
https://support.tipsandtricks-hq.com/forums/topic/delay-between-estore-and-paypal#post-712
August 8, 2016 at 1:57 pm #73751Olik
MemberIt doesn’t seem to be the case with us.. and what about PDT?
August 9, 2016 at 5:39 pm #73752Olik
MemberMaybe it’s somehow connected to Sandbox.. someone posted this at StackOverflow:
“We have multiple sites that uses PayPal standard with PDT and IPN callbacks, when I switch this to sandbox mode things don’t work but works outside of the sandbox.”
Or did you test PDT with Sandbox and saw it working?
August 9, 2016 at 6:16 pm #73753wzp
ModeratorIf you can afford doing 1 or 2 live transactions, for small amounts, do it.
-
AuthorPosts
- You must be logged in to reply to this topic.