I'd like to add monthly, tri-monthly, bi-annualy and annual

I'd like to add monthly, tri-monthly, bi-annualy and annual payment options, possible?

  • hollywooood

    Hi Guys,

    Any chance on adjusting the options for credit billing? There seems to be no flexibility here which is a bit useless in my opinion. I see it's all hard coded in "page-checkout.php" as to how the classified ads get billed. Shouldn't this be up to the site owner?

    I written the following in place of line 53 to 63 in "page-checkout.php:

    <?php
     $amount1 = $options['payments']['cost_credit_1'];
     $amount3 = $options['payments']['cost_credit_3'];
     $amount6 = $options['payments']['cost_credit_6'];
    
    ?>
    
     <option value="1" <?php selected(! empty($_POST['credits_cost_1'] ) && $_POST['credits_cost_1'] == $amount1 ); ?> >1 Credit for <?php echo $amount1 . ' ' . $options['payment_types']['paypal']['currency']; ?></option>
     <option value="3">3 Credits for <?php echo $amount3 . ' ' . $options['payment_types']['paypal']['currency']; ?></option>
     <option value="6">6 Credits for <?php echo $amount6 . ' ' . $options['payment_types']['paypal']['currency']; ?></option>

    I've added this in "settings-payments.php" froms line 126 to 147 for the admin:

    <tr>
    						<th><label for="cost_credit_1"><?php _e( 'Cost Per Credit', $this->text_domain ); ?></label></th>
    						<td>
    							<input type="text" id="cost_credit_1" name="cost_credit_1" value="<?php echo ( empty( $options['cost_credit_1'] ) ) ? '0' : $options['cost_credit_1']; ?>" class="small-text" />
    							<span class="description"><?php _e( 'How much a credit should cost.', $this->text_domain ); ?></span>
    						</td>
    					</tr>
    					<tr>
    						<th><label for="cost_credit_3"><?php _e( 'Cost Per 3 Credits', $this->text_domain ); ?></label></th>
    						<td>
    							<input type="text" id="cost_credit_3" name="cost_credit_3" value="<?php echo ( empty( $options['cost_credit_3'] ) ) ? '0' : $options['cost_credit_3']; ?>" class="small-text" />
    							<span class="description"><?php _e( 'How much 3 credits should cost.', $this->text_domain ); ?></span>
    						</td>
    					</tr>
    					<tr>
    						<th><label for="cost_credit_6"><?php _e( 'Cost Per 6 Credits', $this->text_domain ); ?></label></th>
    						<td>
    							<input type="text" id="cost_credit_6" name="cost_credit_6" value="<?php echo ( empty( $options['cost_credit_6'] ) ) ? '0' : $options['cost_credit_6']; ?>" class="small-text" />
    							<span class="description"><?php _e( 'How much six credits should cost.', $this->text_domain ); ?></span>
    						</td>
    
    					</tr>

    All of which get entered nicely in the DB.

    Now my trouble lies in "payments.php" on lines 266 through 269:

    elseif($_SESSION['billing_type'] == 'credits') {
    					$_SESSION['cost'] = $options['payments']['cost_credit_1'];
    					$_SESSION['credits'] = $_POST['credits'];
    					$_SESSION['billing_agreement'] = "{$_POST['credits']}: " . $options['payments']['description'];
    				}

    Somehow I need to establish that the billing_type does infact =='credits' && $options == 'cost_credit_1". Likewise for the other two elseif statements I would like to add for the other two options I want.

    I can get all the way to the paypal checkout but I need the proper amounts to show up there.

    Any help on this would be HUGE.

  • Saurabh

    Hi @hollywooood,

    I'd like to add monthly, tri-monthly, bi-annualy and annual payment options, possible?

    Adding more billing frequency options isn't a simple workaround. So, I'm passing this on to the developers as a feature request.

    I just need to confirm something for the credits modification. So, you want a different cost for 1, 3 and 6 credits, I can see. So, what would happen when there are 15 or say, 10 credits to process. How would we calculate the total cost then?

    Would it be cost of 6 credits + cost of 3 credits + cost of 1 credit (10 credits)?

    Once you clarify this, I'd be able to help with the code, better.

    Best

    Saurabh

  • Saurabh

    Hi @hollywooood,

    In that case, the modifications would be, as follows:

    page-checkout.php:: No modifications

    settings-payments.php:

    <tr>
    	<th><label for="cost_credit"><?php _e( 'Cost Per Credit', $this->text_domain ); ?></label></th>
    	<td>
    		<input type="text" id="cost_credit_1" name="cost_credit" value="<?php echo ( empty( $options['cost_credit'] ) ) ? '0' : $options['cost_credit']; ?>" class="small-text" />
    		<span class="description"><?php _e( 'How much a credit should cost.', $this->text_domain ); ?></span>
    	</td>
    </tr>
    <tr>
    	<th><label for="discount_1"><?php _e( 'Discount 1', $this->text_domain ); ?></label></th>
    	<td>
    		<input type="text" id="discount_1" name="discount_1" value="<?php echo ( empty( $options['discount_1'] ) ) ? '0' : $options['discount_1']; ?>" class="small-text" /> %
    		<span class="description"><?php _e( 'Discount on 6-11 credits.', $this->text_domain ); ?></span>
    	</td>
    </tr>
    <tr>
    	<th><label for="discount_2"><?php _e( 'Discount 2', $this->text_domain ); ?></label></th>
    	<td>
    		<input type="text" id="discount_2" name="discount_2" value="<?php echo ( empty( $options['discount_2'] ) ) ? '0' : $options['discount_2']; ?>" class="small-text" /> %
    		<span class="description"><?php _e( 'Discount on more than 12 credits', $this->text_domain ); ?></span>
    	</td>
    </tr>

    So, basically we've added two fields for the additional discounts. You could also add other fields for more fine grained control. The idea is to store the discounts in the options table, so we can use it later, as follows:

    payments.php:

    elseif($_SESSION['billing_type'] == 'credits') {
    
    	// how many credits?
    	$credits = $_POST['credits'];
    
    	// calculate discounts
    	$discount = 0;
    
    	if($credits>5 && $credits<12){ // 6-11 credits
    		$discount = $options['payments']['discount_1'];
    	}elseif($credits>11){ // 12 or more
    		$discount = $options['payments']['discount_2'];
    	}
    
    	// calculate cost
    	$cost = $_POST['credits'] * $options['payments']['cost_credit'];
    
    	// apply discount to cost
    	$cost = $cost - ($cost*($discount/100)); // would be zero for 1-5 credits
    
    	// set up session data
    	$_SESSION['cost'] = sprintf( "%01.2f", $cost);
    	$_SESSION['credits'] = $credits;
    	$_SESSION['billing_agreement'] = "{$_POST['credits']}: " . $options['payments']['description'];
    }

    This will apply your discounts, to the final cost before it is processed.

    Do let me how it works out for you or if you need more help.

    Best

    Saurabh

  • hollywooood

    HI and big thanks for the support on this. I've just a quick question I'm sure you can resolve quickly for me.

    I've started from scratch with a new classifieds plugin folder.

    Here is what my settings-payments.php looks like now for the "Use Credits" section:

    <div class="postbox">
    			<h3 class='hndle'><span><?php _e( 'Use Credits', $this->text_domain ) ?></span></h3>
    			<div class="inside">
    				<table class="form-table">
    
    					<tr>
    						<th><label for="enable_credits"><?php _e( 'Enable Credits', $this->text_domain ); ?></label></th>
    						<td>
    							<label>
    								<input type="checkbox" id="enable_credits" name="enable_credits" value="1" <?php checked( ! empty( $options['enable_credits'] ) );  ?> />
    								<?php _e( 'Enable credits for publishing an ad.', $this->text_domain ); ?>
    							</label>
    						</td>
    					</tr>
    					<tr>
    	                    <th><label for="cost_credit"><?php _e( 'Cost Per Credit', $this->text_domain ); ?></label></th>
    	                    <td>
    		                    <input type="text" id="cost_credit_1" name="cost_credit" value="<?php echo ( empty( $options['cost_credit'] ) ) ? '0' : $options['cost_credit']; ?>" class="small-text" />
    		                    <span class="description"><?php _e( 'How much a credit should cost.', $this->text_domain ); ?></span>
    	                    </td>
                        </tr>
                        <tr>
    	                    <th><label for="discount_1"><?php _e( 'Discount 1', $this->text_domain ); ?></label></th>
    	                    <td>
    		                    <input type="text" id="discount_1" name="discount_1" value="<?php echo ( empty( $options['discount_1'] ) ) ? '0' : $options['discount_1']; ?>" class="small-text" /> %
    		                    <span class="description"><?php _e( 'Discount on 6-11 credits.', $this->text_domain ); ?></span>
    	                    </td>
                        </tr>
                        <tr>
    	                    <th><label for="discount_2"><?php _e( 'Discount 2', $this->text_domain ); ?></label></th>
    	                    <td>
    		                    <input type="text" id="discount_2" name="discount_2" value="<?php echo ( empty( $options['discount_2'] ) ) ? '0' : $options['discount_2']; ?>" class="small-text" /> %
    		                    <span class="description"><?php _e( 'Discount on more than 12 credits', $this->text_domain ); ?></span>
    	                    </td>
                        </tr>
    
    					<tr>
    						<th><label for="credits_per_week"><?php _e( 'Credits Per Week', $this->text_domain ); ?></label></th>
    						<td>
    							<input type="text" id="credits_per_week" name="credits_per_week" value="<?php echo ( empty( $options['credits_per_week'] ) ) ? '0' : $options['credits_per_week']; ?>" class="small-text" />
    							<span class="description"><?php _e( 'How many credits you need to publish an ad for one week.', $this->text_domain ); ?></span>
    						</td>
    					</tr>
    					<tr>
    						<th><label for="signup_credits"><?php _e( 'Signup Credits', $this->text_domain ); ?></label></th>
    						<td>
    							<input type="text" id="signup_credits" name="signup_credits" value="<?php echo ( empty( $options['signup_credits'] ) ) ? '0' : $options['signup_credits']; ?>" class="small-text" />
    							<span class="description"><?php _e( 'How many credits a user should receive for signing up.', $this->text_domain ); ?></span>
    						</td>
    					</tr>
    					<tr>
    						<th><label for="description"><?php _e( 'Description', $this->text_domain ); ?></label></th>
    						<td>
    							<textarea class="cf-full" id="description" name="description" rows="1" ><?php echo ( empty( $options['description'] ) ) ? '' : sanitize_text_field($options['description']); ?></textarea>
    							<br />
    							<span class="description"><?php _e( 'Description of the costs and durations associated with publishing an ad. Will be displayed in the admin area.', $this->text_domain ); ?></span>
    						</td>
    					</tr>
    				</table>
    			</div>

    For payments.php I replaced all from line 265 to 269 with the code you gave me.

    On the front end it's now starting at 10 credits for $340.00 all the way to 100 credits at $3400.00.

    What did I do wrong here?

  • Saurabh

    Hi,

    Hope you are having a good day!

    No, you did nothing wrong. It was my bad, actually. I missed this part of your requirement.

    On page-checkout.php, locate this code at about line 52:

    <?php
    for ( $i = 1; $i <= 10; $i++ ):
        $credits = 10 * $i;
        $amount = $credits * $options['payments']['cost_credit'];
    ?>

    This for loop decides the options that you get. It runs 10 times, so you have 10 options. Adjust the $i<=10; to have lesser/more options.

    This line:

    $credits = 10 * $i;

    makes sure that each option is a multiple of 10; adjust this to have better control. You could maybe remove the factor of 10 altogether.

    I also feel I should clarify that the select dropdown will still show a list from where users can choose the actual number of credits, so you could adjust that. If you want a different selection, you can replace the input, as you wish by replacing this whole block of code:

    <select name="credits">
    	<?php
    	for ( $i = 1; $i <= 10; $i++ ):
    	$credits = 10 * $i;
    	$amount = $credits * $options['payments']['cost_credit'];
    	?>
    	<option value="<?php echo $credits; ?>" <?php selected(! empty($_POST['credits_cost'] ) && $_POST['credits_cost'] == $amount ); ?> >
    		<?php echo $credits; ?> Credits for <?php echo sprintf( "%01.2f", $amount) . ' ' . $options['payment_types']['paypal']['currency']; ?>
    	</option>
    	<?php endfor; ?>
    </select>

    Just make sure that the form field's name attribute is still credits and the value is the number of credits that you want to pass.

    After this is sent for further calculations, the discounts would be applied to the total credits selected.

    I hope this helps.

    Best

    Saurabh

  • hollywooood

    OK cool...This is all working nicely now. There is just one more thing on this and that is the way it displays in the option drop downs. It would be nice to reflect the pricing differences instead of listing each one as a $34 increase.

    I have changed the $credits line to:

    $credits = 1 * $i;

    at 6 Credits we should see that the price is $173.40 instead of the $204 shown now. Same situation at 12.

    Any suggestions would be great.

    Thanks for all the help so far..

  • Saurabh

    Hi,

    Good to know that the changes are working well for you!

    To reflect the discounts in the dropdown, itself, we'd need to calculate the discounts here, as well as in payments.php:

    So, the new code for page-checkout.php would be:

    <select name="credits">
    	<?php
    	for ( $i = 1; $i <= 10; $i++ ):
    
    	$credits =  $i;
    
    	// calculate discounts
    	$discount = 0;
    
    	if($credits>5 && $credits<12){ // 6-11 credits
    		$discount = $options['payments']['discount_1'];
    	}elseif($credits>11){ // 12 or more
    		$discount = $options['payments']['discount_2'];
    	}
    
    	// calculate cost
    	$cost = $_POST['credits'] * $options['payments']['cost_credit'];
    
    	// apply discount to cost
    	$amount = $cost - ($cost*($discount/100)); // would be zero for 1-5 credits
    	?>
    	<option value="<?php echo $credits; ?>" <?php selected(! empty($_POST['credits_cost'] ) && $_POST['credits_cost'] == $cost ); ?> >
    		<?php echo $credits; ?> Credits for <?php echo sprintf( "%01.2f", $amount) . ' ' . $options['payment_types']['paypal']['currency']; ?>
    	</option>
    	<?php endfor; ?>
    </select>

    This way, we'd be able to reflect the discounts in the display, as well.

    Do let me know how that works out for you.

    Best

    Saurabh

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.