• Resolved dmaziarz

    (@dmaziarz)


    Hello,
    I’m looking for a function that checks if the element has any child (element inside element).

    Structure XML:

    <sizes>
    <size>S</size>
    <size>L</size>
    </sizes>

    So, basically I just want to check if <sizes> has <size> inside.

    I’ve tried function below, but with no results:

    
     function is_element_empty($element) {
    	if(empty($element)) {
    		return "This element is empty.";
    	} else {
    		return "This element is not empty!";
    	}
    }

    Thank you in advance

    • This topic was modified 3 years, 8 months ago by dmaziarz.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter dmaziarz

    (@dmaziarz)

    Solution was to put{sizes[1]/size[1]} as $element into is_element_empty function.

    @dmaziarz

    Solution was to put{sizes[1]/size[1]} as $element into is_element_empty function.

    I need something similar. Can you provide an example of how you wrote the exact function please?

    • This reply was modified 3 years, 8 months ago by Iamhere.
    Thread Starter dmaziarz

    (@dmaziarz)

    @iamhere Hello
    My function is to check if element <sizes> has something inside. Then it returns “visible” or “hidden”. You have to add it into “Function Editior” in WP All Import’s import settings.

    function is_element_empty($element) {
    	if(empty($element)) {
    		return 'hidden';
    	} else {
    		return 'visible';
    	}
    }

    To use it just put this [is_element_empty({sizes[1]/size[1]})] into WP All import field. The content between { and } is XPATH to your field the XML file.

    • This reply was modified 3 years, 8 months ago by dmaziarz.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Is element empty / has child function’ is closed to new replies.