Address labels — formatting City, State, Zip

About Support Support Address labels — formatting City, State, Zip

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #5383

    Greetings,

    Another quick question about formatting.

    Addresses are stored in a single field which includes the street address, the city, the state, and the zip code. These are separated by commas, so running a post-download filter to put the four pieces of information into individual fields isn’t very difficult. However, this would be easier if we could pass a parameter to the label / csv download module to split those fields into their components, saving the need for another step after the labels are downloaded.

    I’m also curious why the address is conflated rather than being in separate fields? It is easy to concatenate fields, it is a bit more problematic to split them.

    I realize that this plugin is written and maintained in Great Britain, so the address lines will not be the same as in the United States. Is there an equivalent of City, State, Zip which would make the US mailing labels easier to format?

    Thanks.

    #5385
    Avatar for Andy MoyleAndy Moyle
    Keymaster

    Hi there,
    Address formatting for an international plugin is a total nightmare! I use one field because there are lots of ways of ordering the elements of an address in the different nations. See https://en.wikipedia.org/wiki/Address.

    To have individual elements would mean detecting the nation and knowing the order for forms – not everyone bothers setting the locale on their WP install either! I’m in the UK and we have two ways of formatting addresses depending on whether the house has a number or a name!

    The Google map api wants the address as one line so it made sense to make it easy for the user to enter the address simply and store it that way

    The CSV and mailing labels in the plugin just put a line break after each comma.
    A simple str_replace(“,”,”, \r\n”,$address) would work or explode(“,”,$address) to put it in an array for further processing

    #5386

    I modified pdf_creator.php to handle the addresses for both individuals and households. My mods are the same for both. Here is the code for individuals.

    =============================

    foreach ($results as $row)
    {

    $name=implode(” “,array_filter(array($row->first_name.$row->prefix,$row->last_name)));
    $address=$row->address;
    $row->address=str_replace(“, “,”,”,$row->address);
    $add=explode(“,”,$row->address);
    // modified 2/8/2021 to give US style mailing labels
    $street = $add[0];
    $city = $add[1];
    $state = $add[2];
    $zip = $add[3];
    // $add=$name.”\n”.implode(“,\n”,$add);
    $add1=$name.”\n”.$street.”\n”.$city.”, “.$state.” “.$zip;
    // $pdflabel->Add_Label($add);
    $pdflabel->Add_Label($add1);

    }

    $pdflabel->Output();

    //end of mailing labels
    }
    exit();

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.