0

I have a loan calculator plugin that has the below code block. It sets the variable $calcHTML and then returns it to publish it to the screen. It looks like a lot of code but it is really just putting a bunch of html to a variable then returning it.

I want to place my social button from another plugin in the middle of $calcHTML, so that my social button output on the calculator.

The code to output my social buttons is:

Social plugin code

if ( function_exists( 'rtsocial' ) ) { echo rtsocial(); }

How can I use the above function and combine it so that the output will be placed in the $calcHTML variable below?

Calculator code below

add_shortcode('clc_car_loan_calculator', 'clc_car_loan_calculator');

function clc_car_loan_calculator($atts) {

    $queryString = '';

    if(isset($atts['currency'])) {empty($queryString)?$queryString .= '?':$queryString .= '&'; $queryString .= 'currency='.urlencode($atts['currency']);}
    if(isset($atts['theme'])) {empty($queryString)?$queryString .= '?':$queryString .= '&'; $queryString .= 'theme='.urlencode($atts['theme']);}

    $calcHTML = '<div class="clc-widget clc-fp-widget">
                   <form>
                       <table class="clc-input-table">
                           <tr>
                               <td>Vehicle Price</td>
                               <td>
                                   <input type="text" id="clc-fp-car-loan-price" />
                               </td>
                               <td>Down Payment</td>
                               <td>
                                   <input type="text" id="clc-fp-car-loan-down-payment" />
                               </td>
                           </tr>
                           <tr>
                               <td>Trade in Amount</td>
                               <td>
                                   <input type="text" id="clc-fp-car-loan-trade" />
                               </td>
                               <td>Owed on Trade</td>
                               <td>
                                   <input type="text" id="clc-fp-car-loan-trade-owed" />
                               </td>
                           </tr>
                           <tr>
                               <td>Interest Rate</td>
                               <td>
                                   <input type="text" id="clc-fp-car-loan-interest-rate" />
                               </td>
                               <td>Sales Tax Rate</td>
                               <td>
                                   <input type="text" id="clc-fp-car-loan-tax-rate" />
                               </td>
                           </tr>
                           <tr>
                               <td>Term (months)</td>
                               <td>
                                   <input type="text" id="clc-fp-car-loan-term" />
                               </td>
                               <td>Start Date</td>
                               <td>
                                   <input type="text" id="clc-fp-car-loan-start-date" />
                               </td>
                           </tr>
                           <tr>
                               <td colspan="4">
                                   <input type="submit" id="clc-fp-calculate-car-loan-button" value="Calculate" onClick="return false;" />
                               </td>
                           </tr>
                       </table>
                   </form>
                   <table class="clc-fp-display-table">
                       <tr>
                           <td>
                               <h2>Loan Summary</h2>
                               <div id="clcFPCarLoanBreakdownData"></div>
                               <div class="clc-clear-line" style="height:20px;"></div>
                               <table class="clc-full-width">
                                  <tr>
                                     <td class="clc-breakdown-cell">
                                        <div id="clcFPCarLoanBreakdownChart" style="width:180px; height:180px;"></div>
                                     </td>
                                     <td class="clc-balances-cell">
                                        <div id="clcCarLoanPrincipleHeading" class="clc-heading"></div>
                                        <div id="clcCarLoanPrincipleChart" style="width:100%; height:180px;"></div>
                                     </td>
                                  </tr>
                               </table>
                               <div class="clc-clear-line" style="height:30px;"></div>
                               <div id="clcFPCarLoanAmortizationData">
                                   <ul>
                                       <li>
                                           <a href="#clcFPCarLoanYearlyAmortization">Yearly Amortization</a>
                                       </li>
                                       <li>
                                           <a href="#clcFPCarLoanMonthlyAmortization">Monthly Amortization</a>
                                       </li>
                                       <li>
                                           <a href="#clcFPCarLoanLoanDetails">Detailed Summary</a>
                                       </li>
                                   </ul>
                                   <div id="clcFPCarLoanLoanDetails"></div>
                                   <div id="clcFPCarLoanYearlyAmortization"></div>
                                   <div id="clcFPCarLoanMonthlyAmortization"></div>
                                   <div class="clc-clear-line"></div>
                               </div>
                           </td>
                       </tr>
                   </table>
                   <script src="'.plugins_url('/js/bootstrap-fp.js'.$queryString, __FILE__).'" id="clc-fp-car-loan" type="text/javascript"></script>
               </div>';

   return $calcHTML;
}

2 Answers 2

1
if ( function_exists( 'rtsocial' ) ) { $calcvalue =  rtsocial(); }

And in your function

  function clc_car_loan_calculator($atts) {
global $calcvalue;
..
....
......
return $calcHTML.''.$calcvalue;

}
Sign up to request clarification or add additional context in comments.

Comments

0

You need to read about String Operators

If you want to place some content in the middle you need to do it as follows

if ( function_exists( 'rtsocial' ) ) { 
    $calcHTML .=  rtsocial(); 
}

the . operaor is used for the concatination. Your whole function will now look like this

<?php
function clc_car_loan_calculator($atts) {

    $queryString = '';

    if(isset($atts['currency'])) {empty($queryString)?$queryString .= '?':$queryString .= '&amp;'; $queryString .= 'currency='.urlencode($atts['currency']);}
    if(isset($atts['theme'])) {empty($queryString)?$queryString .= '?':$queryString .= '&amp;'; $queryString .= 'theme='.urlencode($atts['theme']);}

    $calcHTML = '<div class="clc-widget clc-fp-widget">
                   <form>
                       <table class="clc-input-table">
                           <tr>
                               <td>Vehicle Price</td>
                               <td>
                                   <input type="text" id="clc-fp-car-loan-price" />
                               </td>
                               <td>Down Payment</td>
                               <td>
                                   <input type="text" id="clc-fp-car-loan-down-payment" />
                               </td>
                           </tr>
                           <tr>
                               <td>Trade in Amount</td>
                               <td>
                                   <input type="text" id="clc-fp-car-loan-trade" />
                               </td>
                               <td>Owed on Trade</td>
                               <td>
                                   <input type="text" id="clc-fp-car-loan-trade-owed" />
                               </td>
                           </tr>
                           <tr>
                               <td>Interest Rate</td>
                               <td>
                                   <input type="text" id="clc-fp-car-loan-interest-rate" />
                               </td>
                               <td>Sales Tax Rate</td>
                               <td>
                                   <input type="text" id="clc-fp-car-loan-tax-rate" />
                               </td>
                           </tr>
                           <tr>
                               <td>Term (months)</td>
                               <td>
                                   <input type="text" id="clc-fp-car-loan-term" />
                               </td>
                               <td>Start Date</td>
                               <td>
                                   <input type="text" id="clc-fp-car-loan-start-date" />
                               </td>
                           </tr>
                           <tr>
                               <td colspan="4">
                                   <input type="submit" id="clc-fp-calculate-car-loan-button" value="Calculate" onClick="return false;" />
                               </td>
                           </tr>
                       </table>
                   </form>';

                   if ( function_exists( 'rtsocial' ) ) { 
                        $calcHTML .=  rtsocial(); 
                    }


    $calcHTML .=    '<table class="clc-fp-display-table">
                       <tr>
                           <td>
                               <h2>Loan Summary</h2>
                               <div id="clcFPCarLoanBreakdownData"></div>
                               <div class="clc-clear-line" style="height:20px;"></div>
                               <table class="clc-full-width">
                                  <tr>
                                     <td class="clc-breakdown-cell">
                                        <div id="clcFPCarLoanBreakdownChart" style="width:180px; height:180px;"></div>
                                     </td>
                                     <td class="clc-balances-cell">
                                        <div id="clcCarLoanPrincipleHeading" class="clc-heading"></div>
                                        <div id="clcCarLoanPrincipleChart" style="width:100%; height:180px;"></div>
                                     </td>
                                  </tr>
                               </table>
                               <div class="clc-clear-line" style="height:30px;"></div>
                               <div id="clcFPCarLoanAmortizationData">
                                   <ul>
                                       <li>
                                           <a href="#clcFPCarLoanYearlyAmortization">Yearly Amortization</a>
                                       </li>
                                       <li>
                                           <a href="#clcFPCarLoanMonthlyAmortization">Monthly Amortization</a>
                                       </li>
                                       <li>
                                           <a href="#clcFPCarLoanLoanDetails">Detailed Summary</a>
                                       </li>
                                   </ul>
                                   <div id="clcFPCarLoanLoanDetails"></div>
                                   <div id="clcFPCarLoanYearlyAmortization"></div>
                                   <div id="clcFPCarLoanMonthlyAmortization"></div>
                                   <div class="clc-clear-line"></div>
                               </div>
                           </td>
                       </tr>
                   </table>
                   <script src="'.plugins_url('/js/bootstrap-fp.js'.$queryString, __FILE__).'" id="clc-fp-car-loan" type="text/javascript"></script>
               </div>';


   return $calcHTML;
}
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.