• Resolved vergedesign

    (@vergedesign)


    Hello. I want there to be a comma between fields ONLY if the fields are present. If they arent present, currently i am getting multiple comma’a. To explain better, an example…

    {addressline1[1]},{addressline2[1]},{city[1]},{county[1]}

    123 york street, Wembley, London, London
    I can add comma’s manually, however if a field (or two is missing), this is the output…

    123 york street,, London, London

Viewing 1 replies (of 1 total)
  • Plugin Author WP All Import

    (@wpallimport)

    Hello @vergedesign,

    There are probably a lot of ways to do this. The first thing I thought of was to use a PHP function:

    function comma_remove(...$addresses) {
    	$str = null;
    	foreach ($addresses as $address) {
    		if ($address != null) {
    			$str = $str . ',' . $address;
    		}
    	}
    	return ltrim($str,",");
    }

    You would use that function like this: [comma_remove({addressline1[1]},{addressline2[1]},{city[1]},{county[1]})]

    You can read more about using PHP functions in your imports here: https://www.wpallimport.com/documentation/developers/execute-php/

Viewing 1 replies (of 1 total)
  • The topic ‘Add a conditional comma between fields if present’ is closed to new replies.