Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // needs: https://github.com/VIISON/AddressSplitting
- add_filter('pr_shipping_dhl_label_args', 'fix_dhl_address', 2, 10);
- function split_address( $address_1, $address_2 ) {
- $split = array();
- // try to split the first adress line
- try {
- $split = \VIISON\AddressSplitter\AddressSplitter::splitAddress( $address_1 );
- } catch ( Exception $e ) {
- // try again with with added field
- try {
- $split = \VIISON\AddressSplitter\AddressSplitter::splitAddress( $address_1 . ' ' .
- $address_2 );
- // address is probably invalid
- } catch (Exception $e) {
- error_log($e->getMessage());
- }
- }
- return $split;
- }
- function fix_dhl_address($args, $order_id) {
- $split = $this->split_address($args['shipping_address']['address_1'], $args['shipping_address']['address_2']);
- if (!empty($split)) {
- $args['shipping_address']['address_1'] = $split['streetName'];
- $args['shipping_address']['address_2'] = $split['houseNumber'];
- } // TODO: handle empty case (invalid address?) or rely on DHL API to handle it?
- return $args;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement