How-To

Hide PayPal button for Free resource

PayPal is enabled or disabled at the component level. 
ABPro is not able to enable PayPal by resource or category. 

 

This How-To shows a way to have either a PayPal button show or a non-Pay Booking Button, depending on if the booking cost is $0 or not.

For this to work you must have ABPro set to display a non-Pay Booking button, set Non-Pay Booking Button = YES in the Payment Processors screen, General Settings tab. 

 

Two steps are required:

  1. On the booking screen, wrap the source code for the buttons in a div tags that can be turned on/off.
  2. Modify the calculation script to hide the appropriate button depending on a $0 or non-$0 booking total cost.

 

Step 1.

Edit the view for the booking screen yo are using, here I am doing the GAD booking screen so I edit file:
\components\com_rsappt_pro2\views\booking_screen_gad\tmpl\default.php

Around line 1014 look for:

<?php if( ($apptpro_config->non_pay_booking_button == "Yes" || ($apptpro_config->authnet_enable == "No"
    && $apptpro_config->enable_paypal == "No"
    && $apptpro_config->_2co_enable == "No"
    ))
    && $apptpro_config->non_pay_booking_button != "DAB" ){ ?>
    <input type="submit" class="button" name="submit" id="submit" onclick="return doSubmit(0);"
        value="<?php echo JText::_('RS1_INPUT_SCRN_SUBMIT');?>"
    <?php if($apptpro_config->requireLogin == "Yes" && $user->guest){ echo "disabled";} ?> />
<?php } ?>
<?php if($apptpro_config->non_pay_booking_button == "DAB"){ ?>
    <input type="submit" class="button" name="submit3" id="submit4" onclick="return doSubmit(1);"
        value="<?php echo JText::_('RS1_INPUT_SCRN_SUBMIT');?>"
    <?php if($apptpro_config->requireLogin == "Yes" && $user->guest){ echo "disabled";} ?> />
    <input type="hidden" id="PayPal_mode" value="DAB" />
<?php } ?>

 

Add red code: 

<div id="NonPayPalButton" style="display: table-cell; padding-left:5px; vertical-align:top; ">
<?php if( ($apptpro_config->non_pay_booking_button == "Yes" || ($apptpro_config->authnet_enable == "No" 

    && $apptpro_config->enable_paypal == "No"
    && $apptpro_config->_2co_enable == "No"
    ))
    && $apptpro_config->non_pay_booking_button != "DAB" ){ ?>
    <input type="submit" class="button" name="submit" id="submit" onclick="return doSubmit(0);" 
        value="<?php echo JText::_('RS1_INPUT_SCRN_SUBMIT');?>" 
    <?php if($apptpro_config->requireLogin == "Yes" && $user->guest){ echo "disabled";} ?> /> 
<?php } ?>
<?php if($apptpro_config->non_pay_booking_button == "DAB"){ ?>
    <input type="submit" class="button" name="submit3" id="submit4" onclick="return doSubmit(1);" 
        value="<?php echo JText::_('RS1_INPUT_SCRN_SUBMIT');?>" 
    <?php if($apptpro_config->requireLogin == "Yes" && $user->guest){ echo "disabled";} ?> /> 
    <input type="hidden" id="PayPal_mode" value="DAB" />
<?php } ?>
</div>

Immediately below that code look for, and add Red code to:

<div id="PayPalButton" style="display: table-cell; padding-left:5px; vertical-align:top; ">
<?php if($apptpro_config->enable_paypal == "Yes"){ 

    if($apptpro_config->paypal_button_url != ""){
        $lang = JFactory::getLanguage();
        $paypal_button_url = str_replace("en_US", str_replace("-", "_", $lang->getTag()), $apptpro_config->paypal_button_url);?>
        <input type="image" id="btnPayPal" align="top" src="/<?php echo $paypal_button_url ?>" border="0" name="submit" alt="submit this form" onclick="return doSubmit(1);"
        <?php if($apptpro_config->requireLogin == "Yes" && $user->guest){ echo "disabled";} ?> >
    <?php } else { ?>
        <input type="submit" class="button" onclick="return doSubmit(1);" name="submit2" id="submit2" value="<?php echo JText::_('RS1_INPUT_SCRN_SUBMIT_PAYPAL');?>"
        <?php if($apptpro_config->requireLogin == "Yes" && $user->guest){ echo " disabled ";} ?> />
    <?php } ?>

<?php } ?>
<?php if($apptpro_config->authnet_enable == "Prod" || $apptpro_config->authnet_enable == "Test"){
    if($apptpro_config->authnet_button_url != ""){
        $authnet_button_url = $apptpro_config->authnet_button_url;?>
        <input type="image" id="btnAuthNet" align="top" src="/<?php echo $authnet_button_url ?>" border="0" name="submit" alt="submit this form" onclick="return doSubmit(2);"
        <?php if($apptpro_config->requireLogin == "Yes" && $user->guest){ echo "disabled";} ?> >
    <?php } else { ?>
        <input type="submit" class="button" onclick="return doSubmit(2);" name="submit3" id="submit3" value="<?php echo JText::_('RS1_INPUT_SCRN_SUBMIT_AUTHNET');?>"
        <?php if($apptpro_config->requireLogin == "Yes" && $user->guest){ echo " disabled ";} ?> />
    <?php } ?>

<?php } ?>
<?php if($apptpro_config->_2co_enable == "Yes"){
    if($apptpro_config->_2co_button_url != ""){
        $_2co_button_url = $apptpro_config->_2co_button_url;?>
        <input type="image" id="btn2Co" align="top" src="/<?php echo $_2co_button_url ?>" border="0" name="submit" alt="submit this form" onclick="return doSubmit(3);"
        <?php if($apptpro_config->requireLogin == "Yes" && $user->guest){ echo "disabled";} ?> >
    <?php } else { ?>
        <input type="submit" class="button" onclick="return doSubmit(3);" name="submit4" id="submit4" value="<?php echo JText::_('RS1_INPUT_SCRN_SUBMIT_2CO');?>"
        <?php if($apptpro_config->requireLogin == "Yes" && $user->guest){ echo " disabled ";} ?> />
    <?php } ?>

<?php }?>
</div>

 

You now have divs around the buttons named PayPalButton and NonPayPalButton.

 

Step 2.

Edit the client side script file:
\components\com_rsappt_pro2\script.js

 

Around line 1636 look fro:

document.getElementById("grand_total").value = (total + fee + extras_total_cost - discount - applied_credit - manual_payment).toFixed(2);

Add the red code..

document.getElementById("grand_total").value = (total + fee + extras_total_cost - discount - applied_credit - manual_payment).toFixed(2);
if(parseFloat(document.getElementById("grand_total").value) == 0){
    document.getElementById("PayPalButton").style.visibility = "hidden";
    document.getElementById("PayPalButton").style.display = "none";
    document.getElementById("NonPayPalButton").style.visibility = "visible";
    document.getElementById("NonPayPalButton").style.display = "";
} else {
    document.getElementById("PayPalButton").style.visibility = "visible";
    document.getElementById("PayPalButton").style.display = "";
    document.getElementById("NonPayPalButton").style.visibility = "hidden";
    document.getElementById("NonPayPalButton").style.display = "none";
}

Now when a user selects a timeslot where the booking cost is $0, only the non-Pay Booking Button will show, if the booking cost is more than $0, the PayPal button will show.