Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

formatting the customer_telephone


zpupster

Recommended Posts

hello,

 

has anyone seen an addon that formats the telephone numbers from the customers database so that when they are called are displayed as (555)555-5555 ?

 

i have been googling and searching for a while now and have not found an answer

Link to comment
Share on other sites

I doubt that there is an addon for that. It would be something coded per site since there are so many ways to do it. I may be wrong though.

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

this the function i used in invoice.php

 

<?php
function format_telephone($phone_number)
{
    $cleaned = preg_replace('/[^[:digit:]]/', '', $phone_number);
    preg_match('/(\d{3})(\d{3})(\d{4})/', $cleaned, $matches);
    return "({$matches[1]}) {$matches[2]}-{$matches[3]}";
}
?>

called it here:

<td class="main"><?php echo format_telephone($order->customer['telephone']); ?></td>

this works,

 

but should i put the function in a different area of oscommerce.  

Link to comment
Share on other sites

Hi -

 you should pop that function into includes/functions/general.php and admin/includes/functions/general.php which would allow you to use it anywhere in the site (you'd also need to remove it from invoice.php)

 

An anternative would be to use a jQuery mask on the create_account/account_edit pages so that the number input would hit the database in your desired format or run your function on the database input from create_account (but that kind of assumes that you only ever,ever,ever get US customers and would screw up existing ones - OK so that's a maybe for a new store :-((  )

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

×
×
  • Create New...