• I start using this plugin and I found out two small bugs

    – 1st “bug” if the address field has no spaces e.g. Opelstrasse3 the label is not codeable so I did this

    $address_exploded = explode(‘ ‘, substr_replace($args[‘shipping_address’][‘address_1’], ‘ ‘, strcspn( $args[‘shipping_address’][‘address_1’] , ‘0123456789’ , 3 ) + 3, 0));

    in file includes/pr-dhl-api/class-pr-dhl-api-soap-label.php line 336

    – 2st “bug” if user has set his address to “address_1” field and a note in “address_2” field then the creation of label fails so my code from line 332 till 359 is:

    // Check address 2 if no parcel shop is being selected
    if ( ! $this->pos_ps && ! $this->pos_rs && ! $this->pos_po ) {
    // If address 2 missing, set last piece of an address to be address 2
    if ( empty( $args[‘shipping_address’][‘address_2’] )) {
    // Break address into pieces
    $address_exploded = explode(‘ ‘, substr_replace($args[‘shipping_address’][‘address_1’], ‘ ‘, strcspn( $args[‘shipping_address’][‘address_1’] , ‘0123456789’ , 3 ) + 3, 0));

    // Loop through address and set number value only…
    // …last found number will be ‘address_2’
    foreach ($address_exploded as $address_key => $address_value) {
    if (is_numeric($address_value)) {
    // Set last index as street number
    $args[‘shipping_address’][‘address_2’] = $address_value;
    $set_key = $address_key;
    }
    }

    // If no number was found, then take last part of address no matter what it is
    if ( empty( $args[‘shipping_address’][‘address_2’] )) {
    $args[‘shipping_address’][‘address_2’] = $address_exploded[ $address_key ];
    $set_key = $address_key;
    }

    // Unset it in address 1
    unset( $address_exploded[ $set_key ] );
    // Set address 1 without street number or last part of address
    $args[‘shipping_address’][‘address_1’] = implode(‘ ‘, $address_exploded );
    } else {
    if ( strpos(trim($args[‘shipping_address’][‘address_2’]), ‘ ‘) !== false ) {

    } else {
    $args[‘shipping_address’][‘address_3’] = $args[‘shipping_address’][‘address_2’];

    // Break address into pieces
    $address_exploded = explode(‘ ‘, substr_replace($args[‘shipping_address’][‘address_1’], ‘ ‘, strcspn( $args[‘shipping_address’][‘address_1’] , ‘0123456789’ , 3 ) + 3, 0));

    // Loop through address and set number value only…
    // …last found number will be ‘address_2’
    foreach ($address_exploded as $address_key => $address_value) {
    if (is_numeric($address_value)) {
    // Set last index as street number
    $args[‘shipping_address’][‘address_2’] = $address_value;
    $set_key = $address_key;
    }
    }

    // If no number was found, then take last part of address no matter what it is
    if ( empty( $args[‘shipping_address’][‘address_2’] )) {
    $args[‘shipping_address’][‘address_2’] = $address_exploded[ $address_key ];
    $set_key = $address_key;
    }

    // Unset it in address 1
    unset( $address_exploded[ $set_key ] );
    // Set address 1 without street number or last part of address
    $args[‘shipping_address’][‘address_1’] = implode(‘ ‘, $address_exploded );
    }
    }
    }

Viewing 1 replies (of 1 total)
  • Plugin Author Shadi Manna

    (@shadim)

    These issues seems to be specific to your online store.

    You can always use the filter “pr_shipping_dhl_label_args” to modify the arguments sent from WooCommerce to the API instead of modifying core files.

Viewing 1 replies (of 1 total)
  • The topic ‘Address Note and address number’ is closed to new replies.