%%user_ip%% not working

I’d like to include the user IP address in the Specific Post/Page Confirmation Email body text but the %%user_ip%% replacement code reurns blank. Anyone got an idea why?

That’s interesting…

If you use the notification’s email, do you se the IP address in the email you get? WP admin > s2Member > API / Notifications > Specific Post/Page ~ Sale Notification > Send An Email Transaction Log Of This Event

:slight_smile:

Using Cloudflare?

If yes, check how to properly set up the headers, depending on how the website is hosted.

Also, it’s possible to quickly check the ips of recently created users or even to register a new dummy user manually and see if the new user gets an ip associated, and which one (if you do it yourself you can verify that it’s correct, the fact there is some ip might not mean it’s the user ip).

It’s been a very long time since I handled this, so I don’t remember the details, but I know there’s tons of tutorials IF that’s the case.

:tulip:

Thanks Cristián for the suggestion. I tried it out. The email I got through was headed, “(s2Member / API Notification Email) - Specific Post/Page ~ Sale”

These values were populated: sp_access_url, sp_access_exp, currency, currency_symbol, amount, txn_id, txn_baid, txn_cid, item_number, item_name, first_name, last_name, full_name, payer_email, cv0

The rest (including &&user_ip%%) were blank.

So, I guess somewhere deeper than I can find, it’s maybe not being captured at all??

Thanks for the update! Okay, now we know the email is not the issue. Let’s look at the payment processing part. Could you show me the shortcode you’re using to sell it?

:slight_smile:

This is kind of you! I don’t use a shortcode. Because of the page construction, I populate the form inputs dynamically when loading the purchase interface (an example is at voyageuse.co.uk). Looking back I can see now that I’m not using the on1 and os1 values:

<form id="buy" target="_parent" action="https://www.paypal.com/cgi-bin/webscr" method="post">
...
<!-- Configures s2Member's Unique Invoice ID/Code  -->
<input type="hidden" name="invoice" value="">
<!-- Associates Purchase With A User/Member (when/if applicable) -->
<input type="hidden" name="on0" value="">
<input type="hidden" name="os0" value="">
<!-- Identifies The Customer's IP Address For Tracking -->
<input type="hidden" name="on1" value="">
<input type="hidden" name="os1" value="">

Is it because these are blank that nothing is coming back to %%user_ip%% ? If so, which ‘value’ do I populate?

I see, you’re using the button’s HTML…

Well, the “Identifies The Customer’s IP Address For Tracking” seems to indicate that, so yeah, it’d be good if you try populating it there.

<!-- Identifies The Customer's IP Address For Tracking -->
<input type="hidden" name="on1" value="<?php echo S2MEMBER_CURRENT_USER_VALUE_FOR_PP_ON1; ?>" />
<input type="hidden" name="os1" value="<?php echo S2MEMBER_CURRENT_USER_VALUE_FOR_PP_OS1; ?>" />

If you don’t have PHP execution, you can try with the s2Get shortcode… https://s2member.com/kb-article/s2get-shortcode-documentation/#toc-3590be65

<!-- Identifies The Customer's IP Address For Tracking -->
<input type="hidden" name="on1" value="[s2Get constant='S2MEMBER_CURRENT_USER_VALUE_FOR_PP_ON1' /]" />
<input type="hidden" name="os1" value="[s2Get constant='S2MEMBER_CURRENT_USER_VALUE_FOR_PP_OS1' /]" />

:slight_smile:

I put the php constants back in and they correctly populated the form before submission - values are (ON1) “Customer IP Address” and (OS1) the correct IP. However the API notification email after sale is the same as before, with %%user_ip%% still blank.
What I’m not sure how to check is if the values are being returned correctly from Paypal via PDT, or if they are not picked up by s2member for the emails.

Thanks for testing that. Okay…

If you have logging enabled, what do the all the related entries say about it? Check the API, the PDT, the RTN, the IPN… Can you show me here the related log entries? (you can edit sensitive details, e.g. real name, email addresses)

:slight_smile:

Cheers Cristián, I haven’t been running logs on the live site (and the dev site doesn’t give me an IP to test against). Which logs should I switch on for these checks?

Just enable s2’s logging in the live site (it’s totally fine for troubleshooting, that’s what it’s meant for), reproduce the behavior. WP Admin > s2Member > Log Files

… and please show me the relevant entries from all the files (or send me the logs by email to support at wpsharks.com and I’ll check them).

:slight_smile:

Hi Cristián, I ran a transaction on the live site with logging turned on. I’ve emailed the logs to you. I see now the IP comes back successfully as ‘option_selection1’ and “Customer IP Address” comes back as ‘option_name1’. What I can’t find yet is where ‘option_selection1’ maps to %%user_ip%% in the API notification and customer email routines.

Thanks for the logs.

I see that the IP address is in the s2-http-api and IPN logs:
[option_selection1] => xxx.x.xxx.xxx

But the [ip] entry is empty. Not sure which of those two the notification is supposed to use. Let me check…

It’d be the [ip] one… And were is it created? Hmm… The IPN handler is trying to get it from option_selection2.

          $paypal['ip'] = (preg_match('/ip address/i', $paypal['option_name2']) && $paypal['option_selection2']) ? $paypal['option_selection2'] : '';

I’m not sure if option_selection2 is supposed to get the value of “on1”, but we can try sending “on2” and see what comes back…

Could you try another test with this for the button?

<!-- Identifies The Customer's IP Address For Tracking -->
<input type="hidden" name="on2" value="[s2Get constant='S2MEMBER_CURRENT_USER_VALUE_FOR_PP_ON1' /]" />
<input type="hidden" name="os2" value="[s2Get constant='S2MEMBER_CURRENT_USER_VALUE_FOR_PP_OS1' /]" />

Not sure if it’ll work, but would like to see what returns in the logs from trying it.

Please add also a value for the os0 and os1, so we see how they come back in the log.

<input type="hidden" name="on0" value="[s2Get constant='S2MEMBER_CURRENT_USER_VALUE_FOR_PP_ON0' /]" />
<input type="hidden" name="os0" value="[s2Get constant='S2MEMBER_CURRENT_USER_VALUE_FOR_PP_OS0' /]" />
<input type="hidden" name="on1" value="[s2Get constant='S2MEMBER_CURRENT_USER_VALUE_FOR_PP_ON1' /]" />
<input type="hidden" name="os1" value="[s2Get constant='S2MEMBER_CURRENT_USER_VALUE_FOR_PP_OS1' /]" />
<input type="hidden" name="on2" value="[s2Get constant='S2MEMBER_CURRENT_USER_VALUE_FOR_PP_ON1' /]" />
<input type="hidden" name="os2" value="[s2Get constant='S2MEMBER_CURRENT_USER_VALUE_FOR_PP_OS1' /]" />

:slight_smile:

Got there, and I think I know where I went wrong.
Originally I think I commented out on0/os0 & on1/os1 because they weren’t doing anything for me.
Then you suggested I add on1/os1 back in. The %%user_ip%% didn’t come through but (I just realised) the IP address appeared on the PayPal sale confirmation (which is what I really need).
Then I added all three value pairs and %%user_ip%% finally came through. However (maybe a coincidence) it broke the return to the originating site.
So I went with the original default of on0/os0 & on1/os1 and everything works.
I guess what’s happening is that the value pairs come through to PayPal in sequence (array?). If the first value pair is missing, the subsequent ones are out of position and get lost. It’s confusing at first because the naming convention is different on the two sides. s2member is keyed to 0 and PayPal is keyed to 1.
Cristián, you’re a champion. Everyone, be nice to this fellow.

1 Like

Great job! I think you’re absolutely right. Well done sorting it out!

Glad I could help. And if you feel like leaving me a rating over at wordpress, that’d be very appreciated. https://wordpress.org/support/plugin/s2member/reviews/

:slight_smile: