Home New Guten Forums WoodMart support forum Invalid argument supplied for foreach() in Swatches.php

Invalid argument supplied for foreach() in Swatches.php

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #83782

    eimulex
    Participant

    Hi,

    When we have a lot of swatches on products we get the invalid argument foreach() in swatches.php.

    Any ideas why is this and how to fix it?

    #83784

    eimulex
    Participant

    Ive managed to fix it temporarely by adding “if(is_array($available_variations)){” before foreach() on line 125 in Swatches.php

    #83794

    Artem Temos
    Keymaster

    Hi,

    Strange, but we can’t reproduce the problem on our side. Could you please send us your FTP access and disable all external plugins so we can check what is wrong there?

    Regards

    #83800

    eimulex
    Participant

    Try adding 50+ swatch variations.

    Please note, that for now, the invalid argument is not present because ive modified the swatches.php file
    See ftp and site logins below in private content:

    #83801

    eimulex
    Participant

    Also, why is it that if i put swatches.php to my child theme in the same folder it does not work?
    As of now ive modified swatches.php in woodmart theme core folder

    #83832

    Artem Temos
    Keymaster

    Try to add the following PHP code snippet to the child theme functions.php

    function woodmart_has_swatches( $id, $attr_name, $options, $available_variations, $swatches_use_variation_images = false ) {
    	$swatches = array();
    
    	foreach ($options as $key => $value) {
    		$swatch = woodmart_has_swatch($id, $attr_name, $value);
    
    		if( ! empty( $swatch ) ) {
    
    			if( $available_variations && $swatches_use_variation_images && woodmart_get_opt( 'grid_swatches_attribute' ) == $attr_name ) {
    
    				$variation = woodmart_get_option_variations( $attr_name, $available_variations, $value );
    
    				$swatch = array_merge( $swatch, $variation);
    			}
    
    			$swatches[$key] = $swatch;
    		}
    	}
    
    	return $swatches;
    }
Viewing 6 posts - 1 through 6 (of 6 total)