Where to Post Custom PHP for prorating (and is the syntax / logic correct)?

Hey everyone,

We are looking to create a custom prorating schedule for our memberships where:

The yearly rate is $150, but prorated on the 15th of each month by 12.50.

ex. Membership fees for January would be $150, fees for February would be 137.50, and fees for March would be $120.00.

We have written this code but are not sure where to place it in s2member (and also are not sure if the logic is correct!)

Any help would be appreciated.

date_default_timezone_set('America/New_York');
$months_in_year = date('t');
$months_left = $months_in_year - date('j');
$prorated_payment = number_format((150 / $months_in_year * $months_left), 2);
echo do_shortcode('[s2Member-Pro-PayPal-Form level="1" ccaps="" desc="1A Membership: This year prorated @ $' . $prorated_payment . ', then $150/year (recurring charge, for ongoing access)" ps="paypal" lc="" cc="USD" dg="0" ns="1" custom="www.cutlerbaybiz.com" ta="' . $prorated_payment . '" tp="' . $months_left . '" tt="D" ra="150" rp="1" rt="M" rr="1" rrt="" rra="2" accept="paypal,visa,mastercard,amex,discover,maestro,solo" accept_via_paypal="paypal" coupon="" accept_coupons="0" default_country_code="" captcha="clean" /]');

It’s a bit difficult to read at the moment. Replace both [hilite pre_code] and [/hilite] with three backticks, i.e. three of these: `

1 Like

Is it easier now? still could use the help.

we’re mainly wondering where we put the code (thinking it should be written as short code in the Paypal Pro Forms section?).

Also not sure if this is the proper syntax, but it doesn’t appear to read the definitions.

date_default_timezone_set('America/New_York');
$months_in_year = date('t');
$months_left = $months_in_year - date('j');
$prorated_payment = number_format(((150 / 12)* $months_left)), 2);
echo do_shortcode ('[s2Member-Pro-PayPal-Form level="1" ccaps="" desc="$150 USD / Yearly (prorated amount @ $ '  . $prorated_payment  . ')" ps="paypal" lc="" cc="USD" dg="0" ns="1" custom="cutlerbaybiz.com" ta="0" tp="0" tt="D" ra="150" rp="1" rt="Y" rr="1" rrt="" rra="2" accept="paypal,visa,mastercard,amex,discover,maestro,solo" accept_via_paypal="paypal" coupon="" accept_coupons="0" default_country_code="" captcha="0" /]');

The way you had the code before was right. You can’t put arbitrary PHP code into s2Member shortcodes.

What I’d suggest is that you use the ezPHP plugin to allow you to paste your earlier code into the page where you want to use it. Just start that code with [php] and end it with [/php].

Once you have it working, you could, if you wish, look to create a shortcode of your own that you could use instead. But I suggest you start with making sure your code works first, using the ezPHP plugin, before you do anything else.

Thanks Tim,
We can now enter the php code using easyphp plugin but are receiving this error:

Parse error: syntax error, unexpected ‘<’ in /home2/cbba/public_html/wp-content/plugins/ezphp/ezphp.php(82) : eval()'d code on line 3

Would you have any suggestions? Much appreciated.

I have just tried this in one of my own development sites, and I am not getting any errors. What version of PHP are you running?

However, I notice that you have [[ and ]] within do_shortcode. These should be just [ and ]

Hey Tim,

We are currently running PHP version: 5.6.30

Just out of curiosity, where did you place the code?

That version of PHP should be fine. I put the code in a page, using the HTML tab. (It shouldn’t make a difference, but I always use the HTML tab.)

Hey Tim,

Very much appreciate your help with this. I’ve just run our code:

date_default_timezone_set('America/New_York');$months_left = $months_in_year - date('m');$prorated_payment = number_format((150 /12) * $months_left),2);echodo_shortcode('[s2Member-Pro-PayPal-Form level="1" ccaps="" desc="1A Membership: This year prorated @ $' . $prorated_payment . ', then $150/year (recurring charge, for ongoing access)" ps="paypal" lc="" cc="USD" dg="0" ns="1"custom="www.cutlerbaybiz.com" ta="' . $prorated_payment . '" tp="' . $months_left . '" tt="D" ra="150" rp="1" rt="M" rr="1" rrt="" rra="2" accept="paypal,visa,mastercard,amex,discover,maestro,solo" accept_via_paypal="paypal" coupon="" accept_coupons="0" default_country_code="" captcha="clean" /]');

through a php code checker (https://phpcodechecker.com/) and it keeps returning this error: PHP Syntax Check: Parse error: syntax error, unexpected ‘date_default_timezone_set’ (T_STRING) in your code on line 2

Thinking that this is the reason the code is not working ion the site but have been unable to correct the syntax.

I found a couple of errors in that code. What I think you want is something like this:

<?php
date_default_timezone_set('America/New_York');
$months_left = $months_in_year - date('m');
$prorated_payment = number_format(150 /12 * $months_left, 2);
echo do_shortcode('[s2Member-Pro-PayPal-Form level="1" ccaps="" desc="1A Membership: This year prorated @ $' . $prorated_payment . ', then $150/year (recurring charge, for ongoing access)" ps="paypal" lc="" cc="USD" dg="0" ns="1"custom="www.cutlerbaybiz.com" ta="' . $prorated_payment . '" tp="' . $months_left . '" tt="D" ra="150" rp="1" rt="M" rr="1" rrt="" rra="2" accept="paypal,visa,mastercard,amex,discover,maestro,solo" accept_via_paypal="paypal" coupon="" accept_coupons="0" default_country_code="" captcha="clean" /]');
?>

But I can see a couple of challenges here too. Have you defined the $months_in_year variable, for example? And does $months_left = $months_in_year - date('m'); return a number? (Because, if not, you can’t multiply with it on the next line.)

By the way, that’s a useful tool. I’m bookmarking it. Thanks!

That seemed to fix the syntax but now were getting another error.
“Invalid form configuration. Missing “desc” attribute. Please provide a Description for this form.”

date_default_timezone_set('America/New_York'); $months_left = $months_in_year - date('m'); $prorated_payment = number_format(150 /12 * $months_left, 2); echo do_shortcode('[s2Member-Pro-PayPal-Form level="1" ccaps=""desc"="Membership prorated @ $' . $prorated_payment . ', then $150/year" ps="paypal" lc="" cc="USD" dg="0" ns="1"custom="www.cutlerbaybiz.com" ta="' . $prorated_payment . '" tp="' . $months_left . '" tt="D" ra="150" rp="1" rt="M" rr="1" rrt="" rra="2" accept="paypal,visa,mastercard,amex,discover,maestro,solo" accept_via_paypal="paypal" coupon="" accept_coupons="0" default_country_code="" captcha="clean" /]');
Im really sorry to keep bothering you. And very appreciative of the help. Thanks!

I think you need a space before desc