Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Recommended Posts

Posted

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

Posted

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.  

Posted

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 :-((  )

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

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...