• Resolved ilyapokrov

    (@ilyapokrov)


    You recently helped me a lot and solved my question.
    If the parameter has the form 35-40 (For example, shoe size is from 35 to 40 sizes), then you need to use the following function:

    function my_output_range( $numbers ) {
    	$range = explode( '-', $numbers );	
    	$return = array();	
    	for ( $i = $range[0]; $i <= $range[1]; $i++ ) {
    		$return[] = $i;
    	}	
    	return implode( '|', $return );
    }

    But there was a problem – in some products a different format of 110x115x65 cm is indicated in the value of this parameter (for example, the size of a backpack).

    If I use the previous code, an error appears – Notice: Undefined offset: 1 in /var/www/***/data/www/site.com.ru/wp-content/uploads/wpallimport/functions.php on line 12 Notice: Undefined offset: 1 in /var/www/***/data/www/…

    How can I solve this problem? So that this formula is activated only if the parameter is written in the form from and to.

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

    (@wpallimport)

    Hi @ilyapokrov,

    How can I solve this problem? So that this formula is activated only if the parameter is written in the form from and to.

    You’ll have to add some sanitization checks to the example function that we sent you. Here’s another example:

    function my_output_range( $numbers ) {
    	if ( strpos( $numbers, '-' ) === false ) return $numbers;
    	$range = explode( '-', $numbers );	
    	if ( count( $range ) != 2 ) return $numbers;
    	
    	if ( ( ! is_numeric( $range[0] ) || ! is_numeric( $range[1] ) ) || $range[1] < $range[0] ) return $numbers;
    	
    	$return = array();	
    	for ( $i = $range[0]; $i <= $range[1]; $i++ ) {
    		$return[] = $i;
    	}	
    	return implode( '|', $return );
    }

    Keep in mind that this is only an example, you’ll have to test and modify the code as needed. We’re happy to post example snippets when we have them, but writing/troubleshooting custom code isn’t something we can help with via these forums.

    Plugin Author WP All Import

    (@wpallimport)

    Hi @ilyapokrov,

    I’m going to mark this as resolved since it has been inactive for a while. Let me know if you still have questions.

    Anyone else that needs help, please open a new topic and we’ll help there.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Parameter value’ is closed to new replies.