Jump to content

Hide Pay button on invoice when due


suportgc

Recommended Posts

Hello good morning, I'd like to know how to hide Pay button on invoice when due

 

 

I need to create a hook for this and I have no programming knowledge.

 

 

I would like to hide the button and if possible insert a message or a button to open called.

 

Ex: Please contact financial support.

 

 

Or a button (Contact financial sector)

 

Can you help me ?

Link to comment
Share on other sites

if it were me, i'd be tempted to just edit the viewinvoice.tpl template and change...

                    {if $status eq "Unpaid" || $status eq "Draft"}
                       <div class="small-text">
                           {$LANG.invoicesdatedue}: {$datedue}
                       </div>
                       <div class="payment-btn-container" align="center">
                           {$paymentbutton}
                       </div>
                   {/if}

to...

                    {if $status eq "Unpaid" || $status eq "Draft"}
                       <div class="small-text">
                           {$LANG.invoicesdatedue}: {$datedue}
                       </div>
                       {if {$date|date_format:"%d/%m/%y"} lt {$duedate|date_format:"%d/%m/%y"}}
                       <div class="payment-btn-container" align="center">
                           {$paymentbutton}
                       </div>
                       {/if}
                   {/if}

that should hide the button...

Link to comment
Share on other sites

Just to facilitate.

The support team gave me the second message.

 

If you were to go down the route of using an action hook, I imagine you might be best using the ClientAreaPageViewInvoice hook point.

 

The paymentbutton variable may be an available variable in that hook point, in which case the value could potentially be modified to based upon the duedate value to display such a message in place of the payment button.

 

But I do not know how to put this information together.

Link to comment
Share on other sites

Got it.

I am wanting to do as a hook, so I do not have problems with updates.

but you've renamed the theme, so updates won't affect this code! :)

and updates can affect any code, template or hook... hooks are never a 100% guarantee of preventing update issues.

 

Can you tell me how to do it?

I posted the Smarty code because it was shorter and quicker, but if you really want to do it as a hook - to remove the button on overdue invoices...

<?php

# Invoice Hide Pay Button Hook
# Written by brian!

function invoice_hide_button_hook($vars)
{
   $today = strtotime($vars['date']);
   $duedate = strtotime($vars['duedate']);

   if($today > $duedate) {
       return array("paymentbutton" => "");
   }
}
add_hook("ClientAreaPageViewInvoice", 1, "invoice_hide_button_hook");

 

What about displaying the new message, how can I do it?

if you want to display a message (you might need to add css styling to this)...

<?php

# Invoice Hide Pay Button Hook
# Written by brian!

function invoice_hide_button_hook($vars)
{
   $today = strtotime($vars['date']);
   $duedate = strtotime($vars['duedate']);

   if($today > $duedate) {
       return array("paymentbutton" => "This is a message...");
   }
}
add_hook("ClientAreaPageViewInvoice", 1, "invoice_hide_button_hook");

if you want to use a link to the contact page as the output...

<?php

# Invoice Hide Pay Button Hook
# Written by brian!

function invoice_hide_button_hook($vars)
{
   $today = strtotime($vars['date']);
   $duedate = strtotime($vars['duedate']);

   if($today > $duedate) {
       return array("paymentbutton" => '<a href="contact.php">Contact Us</a>');
   }
}
add_hook("ClientAreaPageViewInvoice", 1, "invoice_hide_button_hook");

and if you want to use a button, then that's just some different HTML to replace the above href code - there are many ways to do that and i'm sure Googling will tell you more about the usable options, but one way would be to use Bootstrap...

<?php

# Invoice Hide Pay Button Hook
# Written by brian!

function invoice_hide_button_hook($vars)
{
   $today = strtotime($vars['date']);
   $duedate = strtotime($vars['duedate']);

   if($today > $duedate) {
       return array("paymentbutton" => '<a href="contact.php" class="btn btn-default">Contact Us</a>');
   }
}
add_hook("ClientAreaPageViewInvoice", 1, "invoice_hide_button_hook");

Sym8knm.png

Link to comment
Share on other sites

If it's not uncomfortable, could you tell me what I should study to learn these kinds of changes?

Focusing on this part of hooks

there's no quick way to learn....

 

you can take a look at https://developers.whmcs.com/hooks/ and that will walk you through the basics... ideally, you'll need some PHP knowledge, and would be helpful if you understood some SQL and how the database tables can be queried to get the information you want.

 

the best thing to do is just play around with them - perhaps take some hooks posted here by myself or sentq, see what they do, figure out how they work and try to tweak them.

 

though ideally don't do this on a live production site - as an incorrectly coded hook will blank out your client and/or admin areas!

Link to comment
Share on other sites

but you've renamed the theme, so updates won't affect this code! :)

and updates can affect any code, template or hook... hooks are never a 100% guarantee of preventing update issues.

 

 

I posted the Smarty code because it was shorter and quicker, but if you really want to do it as a hook - to remove the button on overdue invoices...

<?php

# Invoice Hide Pay Button Hook
# Written by brian!

function invoice_hide_button_hook($vars)
{
   $today = strtotime($vars['date']);
   $duedate = strtotime($vars['duedate']);

   if($today > $duedate) {
       return array("paymentbutton" => "");
   }
}
add_hook("ClientAreaPageViewInvoice", 1, "invoice_hide_button_hook");

 

 

if you want to display a message (you might need to add css styling to this)...

<?php

# Invoice Hide Pay Button Hook
# Written by brian!

function invoice_hide_button_hook($vars)
{
   $today = strtotime($vars['date']);
   $duedate = strtotime($vars['duedate']);

   if($today > $duedate) {
       return array("paymentbutton" => "This is a message...");
   }
}
add_hook("ClientAreaPageViewInvoice", 1, "invoice_hide_button_hook");

if you want to use a link to the contact page as the output...

<?php

# Invoice Hide Pay Button Hook
# Written by brian!

function invoice_hide_button_hook($vars)
{
   $today = strtotime($vars['date']);
   $duedate = strtotime($vars['duedate']);

   if($today > $duedate) {
       return array("paymentbutton" => '<a href="contact.php">Contact Us</a>');
   }
}
add_hook("ClientAreaPageViewInvoice", 1, "invoice_hide_button_hook");

and if you want to use a button, then that's just some different HTML to replace the above href code - there are many ways to do that and i'm sure Googling will tell you more about the usable options, but one way would be to use Bootstrap...

<?php

# Invoice Hide Pay Button Hook
# Written by brian!

function invoice_hide_button_hook($vars)
{
   $today = strtotime($vars['date']);
   $duedate = strtotime($vars['duedate']);

   if($today > $duedate) {
       return array("paymentbutton" => '<a href="contact.php" class="btn btn-default">Contact Us</a>');
   }
}
add_hook("ClientAreaPageViewInvoice", 1, "invoice_hide_button_hook");

Sym8knm.png

 

 

 

Hey Brian, how's it going?

 

Unfortunately the code is not working 100%

 

Some invoices already expired, show the button to pay.

 

Look

15.png

16.png

17.png

 

what could it be ?

 

<?php

# Invoice Hide Pay Button Hook
# Written by brian!

function invoice_hide_button_hook($vars)
{
   $today = strtotime($vars['date']);
   $duedate = strtotime($vars['duedate']);

   if($today > $duedate) {
       return array("paymentbutton" => '<a href="submitticket.php?step=2&deptid=2" class="btn btn-danger">Contate-nos</a>');
   }
}
add_hook("ClientAreaPageViewInvoice", 1, "invoice_hide_button_hook");

Link to comment
Share on other sites

<?php

function invoice_hide_button_hook($vars)
{	 
if (new DateTime() > DateTime::createFromFormat('d/m/Y', $vars['duedate']))
{
	return array("paymentbutton" => '<a href="submitticket.php?step=2&deptid=2" class="btn btn-danger">Contate-nos</a>');
}	   

}
add_hook("ClientAreaPageViewInvoice", 1, "invoice_hide_button_hook");

 

Screenshot https://prnt.sc/gcz5ux

Link to comment
Share on other sites

<?php

function invoice_hide_button_hook($vars)
{	 
if (new DateTime() > DateTime::createFromFormat('d/m/Y', $vars['duedate']))
{
	return array("paymentbutton" => '<a href="submitticket.php?step=2&deptid=2" class="btn btn-danger">Contate-nos</a>');
}	   

}
add_hook("ClientAreaPageViewInvoice", 1, "invoice_hide_button_hook");

 

Screenshot https://prnt.sc/gcz5ux

 

Perfect.

 

Thank you Edvan.

 

Problem solved.

 

- - - Updated - - -

 

Thank you for helping everyone.

 

Brian, as Edvan checked, on my dashboard did not work, because my date version is d/m/Y.

Brazilian pattern.

 

Thank you all for the solution.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated