OK
Well, let me say that PayPal does not make this easy.
1. They don’t allow trial periods over about 90 days if you are using the ‘D’ option.
2. They don’t allow second trial periods with no payment ($0.00).
Here is what, in my attempt, has to be done.
1. Create a trial period in MONTHS for the remaining months until July 1. Charge the full or reduced price, depending on the current month.
2. Create a second period in DAYS to run off any remaining days in June. Charge a $0.01 fee for paypal to accept the second trial period.
3. Set the standard rate and time period of 1 year that *should* start on July 1.
Now, to the code:
s2member doesn’t accept a second trial period. I don’t know if it matters if you add one or not, but it’s not an option in their button builder (at least not free).
NOTE: I’m on the free version of s2member and even then, the following code has only been minimally tested. I do not claim it’s perfection but it seemed to work for me in initial tests:
Basically, I’ve created a few functions along with a shortcode that you *should* be able to use to do what you want.
First, the shortcode:
[equal-time-pp full='' part='' code='']
This is the shortcode you use to place your buttons on the page/post.
3 Variables are available… really required.
1. full – This is the full amount you charge with trailing zeros. Example: 50.00
2. part – This is the partial payment you charge for Jan. – June registrations. Same format as above.
3. code – This is the s2member shortcode you can generate in the paypal button generator in s2member. NOTE: do not use the “[” or “/]” tags… just copy everything else in between them.
EXAMPLE S2MEMBER SHORTCODE:
[s2Member-PayPal-Button level="1" ccaps="" desc="." ps="paypal" lc="" cc="USD" dg="0" ns="1" custom="" ta="5.00" tp="1" tt="D" ra="10.00" rp="1" rt="Y" rr="1" rrt="" rra="1" image="default" output="button" /]
ONLY COPY THIS:
s2Member-PayPal-Button level="1" ccaps="" desc="." ps="paypal" lc="" cc="USD" dg="0" ns="1" custom="" ta="5.00" tp="1" tt="D" ra="10.00" rp="1" rt="Y" rr="1" rrt="" rra="1" image="default" output="button"
SO THE NEW SHORTCODE WOULD LOOK LIKE THIS:
[equal-time-pp full='50.00' part='30.00' code='s2Member-PayPal-Button level="1" ccaps="" desc="." ps="paypal" lc="" cc="USD" dg="0" ns="1" custom="" ta="5.00" tp="1" tt="D" ra="10.00" rp="1" rt="Y" rr="1" rrt="" rra="1" image="default" output="button"']
Clear as MUD? lol!
Now, you need to add this code probably to your functions.php file. It’s php code so make sure it’s inside the starting and ending php tags.
THE CODE:
function equal_time_pp_form($atts){
extract( shortcode_atts( array(
'full' => '0.01',
'part' => '0.01',
'code' => '[s2Member-PayPal-Button /]',
), $atts ) );
$full_price = $full; //full year membership
$partial_price = $part; //half year membership
$code = '['.$code.' /]';
//This assumes full payment
$first_trial_price = $full_price;
//Calculate number of days through June 30.
$month = date("n");
//Get the number of days for second trial
//Or first trial if less than 1 month
$trial_days = trial_days();
//Check what time of year current month is in
if($month >= 7){
//Add 6 months to first trial if after June 30
$pay_months = (12 - $month) + 6;
}
else {
//Months before June 30
$pay_months = 6 - $month;
//This is the short-term price for Jan - June.
$first_trial_price = $partial_price;
}
//Set Trial Info
if($pay_months == 0){
$first_trial_time = $trial_days;
$first_trial_type = 'D';
$first_trial_amount = $first_trial_price;
$second_trial_time = $trial_days;
$second_trial_type = 'D';
$second_trial_amount = '0.01';
$normal_time = '1';
$normal_type = 'Y';
$normal_amount = $full_price;
}
else {
$first_trial_time = $pay_months;
$first_trial_type = 'M';
$first_trial_amount = $first_trial_price;
$second_trial_time = $trial_days;
$second_trial_type = 'D';
$second_trial_amount = '0.01';
$normal_time = '1';
$normal_type = 'Y';
$normal_amount = $full_price;
}
/* REPLACE SHORTCODE INFO WITH TRIAL INFO */
$code = preg_replace('/ta=".*?"/','ta="'.$first_trial_amount.'"', $code);
$code = preg_replace('/tp=".*?"/','tp="'.$first_trial_time.'"', $code);
$code = preg_replace('/tt=".*?"/','tt="'.$first_trial_type.'"', $code);
$code = preg_replace('/ra=".*?"/','ra="'.$normal_amount.'"', $code);
$code = preg_replace('/rp=".*?"/','rp="'.$normal_time.'"', $code);
$code = preg_replace('/rt=".*?"/','rt="'.$normal_type.'"', $code);
//Add Hack to Include 2nd Trial
add_action('ws_plugin__s2member_during_sc_paypal_button','edit_paypal_form');
//Run modified s2member shortcode
$pp_form = do_shortcode($code);
//Remove Second Trial Hack To Keep From Affecting Other Forms
remove_action('ws_plugin__s2member_during_sc_paypal_button','edit_paypal_form');
//Send form to browser
return $pp_form;
}
add_shortcode('equal-time-pp','equal_time_pp_form');
function edit_paypal_form($vars=array())
{
//Second Trial Variables
$second_trial_time = trial_days();
$second_trial_type = 'D';
$second_trial_amount = '0.01';
//Extra Code Added To S2Member PP Form
$extra_items = ' ';
//Replace With New Code
$new_code = str_replace("",$extra_items,$vars['code']);
//Upate PP Form Code
$vars['code'] = $new_code;
}
function trial_days(){
//Get number of days left in June
$day = date("d");
if($day > 30){
$day = 30;
}
//Have to use 32 to make Paypal work right... I think.
$trial_days = 32 - $day;
return $trial_days;
}
Whew! That took a lot longer than I thought and of course, no guarantee it’s perfect but it seems it can be done… somehow.
LOL!
Dave
-
This reply was modified 4 years, 10 months ago by
David Welch.