Jump to content

Hide date range in invoice emails - on new domain name orders


Recommended Posts

Would it be possible to hide date range in invoice emails (only for new domain orders)?
By default "Expiry Date" should be empty if a NEW domain name order is received e.g.
00/00/0000

Following hook removes the date range for all invoices ... I just want to remove the date for "Domain name" items and only when the "Expiry Date" is 00/00/0000.
https://github.com/Katamaze/WHMCS-Action-Hook-Factory/blob/master/hooks/noDatesInInvoiceItemsDescription.php

It doesn't work with the Smarty email templates, so, I’d like to apply a similar condition into this hook ... any idea?

{if $domain_expiry_date eq "00/00/0000"}

 

<?php

/**
 * No Dates in Invoice Items Description
 *
 * @package     WHMCS
 * @copyright   Katamaze
 * @link        https://katamaze.com
 * @author      Davide Mantenuto <info@katamaze.com>
 */

use WHMCS\Database\Capsule;

add_hook('InvoiceCreationPreEmail', 1, function($vars) {

    $items = Capsule::table('tblinvoiceitems')->select('id', 'description')->where('invoiceid', '=', $vars['invoiceid'])->get();

    if (!$items) {

        return;
    }

    $dateFormat = Capsule::table('tblconfiguration')->select('value')->where('setting', '=', 'DateFormat')->first();

    if (in_array($dateFormat->value, [ 'DD/MM/YYYY', 'DD.MM.YYYY', 'DD-MM-YYYY' ])) {

        $regex = '/[" "][(](((0[1-9]|[12][0-9]|3[01])[- \/.](0[13578]|1[02])|(0[1-9]|[12][0-9]|30)[- \/.](0[469]|11)|(0[1-9]|1\d|2[0-8])[- \/.]02)[- \/.]\d{4}|29[- \/.]02[- \/.](\d{2}(0[48]|[2468][048]|[13579][26])|([02468][048]|[1359][26])00))[\w -]*[-]*[\w -](((0[1-9]|[12][0-9]|3[01])[- \/.](0[13578]|1[02])|(0[1-9]|[12][0-9]|30)[- \/.](0[469]|11)|(0[1-9]|1\d|2[0-8])[- \/.]02)[- \/.]\d{4}|29[- \/.]02[- \/.](\d{2}(0[48]|[2468][048]|[13579][26])|([02468][048]|[1359][26])00))[)]/';
    }
    elseif ($dateFormat->value == 'MM/DD/YYYY') {

        $regex = '/[" "][(](((0[13578]|1[02])|(0[1-9]|[12][0-9]|30)[-\/.](0[469]|11)|(0[1-9]|1\d|2[0-8])[-\/.]02)[-\/.](0[1-9]|[12][0-9]|3[01])[-\/.]\d{4}|29[-\/.]02[-\/.](\d{2}(0[48]|[2468][048]|[13579][26])|([02468][048]|[1359][26])00))[\w -]*[-]*[\w -](((0[13578]|1[02])|(0[1-9]|[12][0-9]|30)[-\/.](0[469]|11)|(0[1-9]|1\d|2[0-8])[-\/.]02)[-\/.](0[1-9]|[12][0-9]|3[01])[-\/.]\d{4}|29[-\/.]02[-\/.](\d{2}(0[48]|[2468][048]|[13579][26])|([02468][048]|[1359][26])00))[)]/';
    }
    elseif (in_array($dateFormat->value, [ 'YYYY/MM/DD', 'YYYY-MM-DD' ])) {

        $regex = '/[" "][(](\d{4}|29[-\/.]02[-\/.](\d{2}(0[48]|[2468][048]|[13579][26])|([02468][048]|[1359][26])00))[-\/.]((0[13578]|1[02])|(0[1-9]|[12][0-9]|30)[-\/.](0[469]|11)|(0[1-9]|1\d|2[0-8])[-\/.]02)[-\/.](0[1-9]|[12][0-9]|3[01])[\w -]*[-]*[\w -](\d{4}|29[-\/.]02[-\/.](\d{2}(0[48]|[2468][048]|[13579][26])|([02468][048]|[1359][26])00))[-\/.]((0[13578]|1[02])|(0[1-9]|[12][0-9]|30)[-\/.](0[469]|11)|(0[1-9]|1\d|2[0-8])[-\/.]02)[-\/.](0[1-9]|[12][0-9]|3[01])[)]/';
    }

    foreach ($items AS $v) {

        $v->description = preg_replace($regex, '', $v->description);
        Capsule::table('tblinvoiceitems')->where('id', '=', $v->id)->update([ 'description' => $v->description ]);
    }
});

 

 

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