• Resolved Vladinator

    (@alexpty)


    Hello, i am really stuck with this, need some help. i have custom XML export like this part:

    <details>
    <type>{Categories}</type>
    <bedrooms>{bedrooms-search}</bedrooms>
    <bathrooms>{property_bathrooms}</bathrooms>
    </details>

    all i need is when {Categories} is “Commercial”, change it to “Business”.

    What’s the best way to do this? Thank you

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

    (@wpallimport)

    Hey @alexpty,

    all i need is when {Categories} is “Commercial”, change it to “Business”.

    You can use a PHP function on the {Categories} element to do that: https://www.wpallimport.com/documentation/export/pass-data-through-php-functions/.

    For example, if the only category with “Commercial” in it is the “Commercial” category, this should work:

    <type>[str_replace("Commercial","Business",{Categories})]</type>

    Thread Starter Vladinator

    (@alexpty)

    Thank you, it’s so simple and works! Could to point me to If/Then statement documentation, or maybe show an example. I have another conditional replacement to make:

    <Type>{Type}</Type>
    ?<prices>?
    ?<price? ?tenure?=?”sale”? ?currency?=?”THB”?>?{property_price}</price>?
    ?<price? ?tenure?=?”rent”? ?currency?=?”THB”? ?period?=?”monthly”?>{property_price}?</price>?
    ?</prices>?

    Since i have only one {property_price}, i need to fill <price> variable depending on {Type}, which is Sale or Rent

    cannot figure this one:

    if {Type} = Rent
    ?<price? ?tenure?=?”rent”? ?currency?=?”THB”? ?period?=?”monthly”?>{property_price}?</price>
    otherwise
    ?<price? ?tenure?=?”sale”? ?currency?=?”THB”?>?{property_price}</price>

    Thank you

    • This reply was modified 3 years, 8 months ago by Vladinator.
    • This reply was modified 3 years, 8 months ago by Vladinator.
    Plugin Author WP All Import

    (@wpallimport)

    Hey @alexpty,

    Could to point me to If/Then statement documentation

    You can read about if/else statements here: https://www.wpallimport.com/documentation/advanced/if-statements/ (the same syntax is used in custom XML exports).

    For this case, I’d suggest outputting the XML with a PHP function. Here’s an untested example function that you can modify as needed:

    function my_output_price( $type, $price ) {
    	$xml = '';
    	if ( $type == "Rent" ) {
    		$xml = '**LT**price tenure="rent" currency="THB" period="monthly"**GT**' . $price . '**LT**/price**GT**';
    	} else {
    		$xml = '**LT**price tenure="sale" currency="THB"**GT**' . $price . '**LT**/price**GT**';
    	}
    	return $xml;
    }

    You’d use it in the XML template, where the “price” tag should be, like this:

    [my_output_price({Type},?{property_price})]

    Just be sure to turn off CDATA tags: https://d.pr/i/CsrTB9.

    Plugin Author WP All Import

    (@wpallimport)

    Hey @alexpty,

    I’m marking this as resolved since it’s been inactive for a while. Please open up a new topic if you still have questions.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘If… then or replace statements’ is closed to new replies.