• The code you previously provided made the Country and City fields optional, and changed the Address field to accept latitude and longitude. However, after making these fields optional, I noticed that when navigating to the location using the latitude and longitude, two extra commas (,,) appear after the coordinates. Is there a way to remove these extra commas?

    add_filter( 'wpsl_meta_box_fields', 'custom_meta_box_fields' );

    function custom_meta_box_fields( $meta_fields ) {

    /**
    * If no 'type' is defined it will show a normal text input field.
    *
    * Supported field types are checkbox, textarea and dropdown.
    */
    $meta_fields[ __( 'Location', 'wpsl' ) ] = array(
    'address' => array(
    'label' => __( 'Address', 'wpsl' ),
    ),
    'address2' => array(
    'label' => __( 'Address 2', 'wpsl' )
    ),
    'city' => array(
    'label' => __( 'City', 'wpsl' ),
    ),
    'state' => array(
    'label' => __( 'State', 'wpsl' )
    ),
    'zip' => array(
    'label' => __( 'Zip Code', 'wpsl' )
    ),
    'country' => array(
    'label' => __( 'Country', 'wpsl' )
    ),
    'country_iso' => array(
    'type' => 'hidden'
    ),
    'lat' => array(
    'label' => __( 'Latitude', 'wpsl' )
    ),
    'lng' => array(
    'label' => __( 'Longitude', 'wpsl' )
    )
    );
    return $meta_fields;

    }

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi there, thanks for writing.

    Are you referring to a previous thread in this forum? If so, could you please send a link so I can have a look at the original thread?
    Many thanks,

    Thread Starter weking

    (@weking)

    farroyo

    (@farroyob)

    Hi again, thanks for getting back.

    If you are comfortable with coding, the only solution for you is to edit some of the plugin’s javascript files

    The issue is here. As you see, it builds the destinationAddress, but since on address exists, you end up with the ,,. If you check if the destinationAddress only contains ,, and then set it to ”, it should probably be fixed.

    There will be a build in fix for this in the 3.0 update.

    Let us know if that does not help.
    Best regards,

    Thread Starter weking

    (@weking)

    Even after adding the code snippet, the issue persists.


    add_filter( ‘wpsl_get_directions_url’, function( $url, $location ) {
    $decoded = urldecode( $url );
    $decoded = str_replace([‘,,’, ‘, ,’], ‘,’, $decoded);
    $decoded = rtrim($decoded, ‘, ‘);
    return esc_url( $decoded );
    }, 10, 2 );

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Removing Extra Commas from Geolocation Input’ is closed to new replies.