Hello Support and other s2member users,
After reading up on other coding examples and the s2member documentation, I ended up using an alternate solution which I think is much better, less coding and the user won’t have to go through two step process to get to Paypal’s payment page. It also resolves a formatting issue I was having with the Paypal button, but that may be related to my theme.
PREREQUISITE: If you offer an annual Level 1 membership and you want to automatically calculate the amount a user would have to pay to upgrade to an annual Level 2 membership.
WHAT IT DOES: Calculates a Level 1 user’s PAID REGISTRATION DAYS which is then subtracted from 365 and then multiplied with the daily rate of that subscription. This figure is the user’s credit amount toward Level 2 subscription. The prorated rate (for upgrading to Level 2) is calculated by subtracting this credit amount from the Level 2 subscription fee. It shows the prorated fee to only Level 1 members. For free subscribers it shows a link for each of the paid subscriptions.
WHERE IT GOES: You can place the code below in your members options page or a separate page that you members can call up.
<?php
$PlusFee = 49.95; // Enter subscription fee for Level 1 membership
$PremFee = 79.95; // Enter subscription fee for Level 2 membership
$PlusDailyRate = .13685; // Enter daily rate based on level 1 subscription fee divided by 365
$PlusCredit = ((365 - S2MEMBER_CURRENT_USER_PAID_REGISTRATION_DAYS) * $PlusDailyRate);
$PremCharges = $PremFee - $PlusCredit;
$PremCharges = round($PremCharges,2); //round off number to 2 decimal points
?>
<?php
if (S2MEMBER_CURRENT_USER_ACCESS_LEVEL === 1){ ?>
<?php if(S2MEMBER_CURRENT_USER_PAID_REGISTRATION_DAYS >= 0){ ?>
<a href="[s2Member-PayPal-Button level="2" ccaps="" desc="Prorated Upgrade from Plus to Premier membership for one year for $<?php echo esc_attr($PremCharges); ?>" ps="paypal" lc="" cc="USD" dg="0" ns="1" custom="your.domain.com" ta="0" tp="0" tt="D" ra="<?php echo esc_attr($PremCharges); ?>" rp="1" rt="Y" rr="0" rrt="" rra="1" image="default" output="url" /]">Upgrade to Premier for only $<?php echo esc_attr($PremCharges); ?>!</a>
<?php } ?>
<?php } elseif (S2MEMBER_CURRENT_USER_ACCESS_LEVEL === 0){ ?>
<a href="[s2Member-PayPal-Button level="1" ccaps="" desc="Plus membership for one year access, non-recurring (one time charge)" ps="paypal" lc="" cc="USD" dg="0" ns="1" custom="your.domain.com" ta="0" tp="0" tt="D" ra="49.95" rp="1" rt="Y" rr="0" rrt="" rra="1" image="default" output="url" /]">Upgrade to Plus member today!</a>
or
<a href="[s2Member-PayPal-Button level="2" ccaps="" desc="Premier membership for one year with automatic yearly recurring charges for ongoing access." ps="paypal" lc="" cc="USD" dg="0" ns="1" custom="your.domain.com" ta="0" tp="0" tt="D" ra="79.95" rp="1" rt="Y" rr="1" rrt="" rra="1" image="default" output="url" /]">Upgrade to Premier status for immediate access to over 4000 audio files!</a>
<?php } ?>
NOTE: output=”url” if you want to use text instead of the Paypal image.
I’m now working on including my own “Buy Now!” image instead of the text. Just thought to share just in case someone else was looking to do the same :)