Home Forums WoodMart support forum Getting error from the swatches module

Getting error from the swatches module

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #105062

    dotcominfo
    Participant

    I’ve obtained another license for a new site I’m building for a medical products manufacturer, and I’m re-themeing their existing site with WoodMart, which means all the product data was originally set up with another theme. I don’t know if that has anything to do with the error I’m getting. I just wanted to give you a little background.

    I checked all settings that have anything to do with swatches and it’s all turned off. So… I need your help in figuring out how to solve this error (what’s causing it – how to get rid of it).

    Here’s the error:
    Warning: Invalid argument supplied for foreach() in /home/svsimage/public_html/dsc/wp-content/themes/woodmart/inc/integrations/woocommerce/modules/swatches.php on line 277

    Thank you!

    #105068

    Artem Temos
    Keymaster

    Hello,

    Thank you so much for purchasing our theme and contacting our support center.

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

    function woodmart_get_active_variations( $attribute_name, $available_variations ) {
    		$results = array();
    
    		if ( ! $available_variations ) {
    			return $results;
    		}
    
    		foreach ( $available_variations as $variation ) {
    			$attr_key = 'attribute_' . $attribute_name;
    			if ( isset( $variation['attributes'][ $attr_key ] ) ) {
    				$results[] = $variation['attributes'][ $attr_key ];
    			}
    		}
    
    		return $results;
    	}

    Kind Regards
    XTemos Studio

    #105218

    dotcominfo
    Participant

    I tried doing this – but there was a problem. WordPress said:

    Your PHP code changes were rolled back due to an error on line 19 of file wp-content/themes/woodmart-child/functions.php. Please fix and try saving again.

    syntax error, unexpected ‘if’ (T_IF)

    #105222

    Artem Temos
    Keymaster

    Please, send us your admin and FTP access so we can check it.

    #105244

    dotcominfo
    Participant

    Here you go. (in the private content)

    #105262

    Artem Temos
    Keymaster

    Hi,

    We have added the code and there is no more error now.

    Regards

    #105384

    dotcominfo
    Participant

    Fantastic! What was the syntax error in the code? Just curious.

    Thank you for the great support.

    #105417

    Artem Temos
    Keymaster

    We didn’t change anything, just copy and paste the code 🙂

    #105419

    dotcominfo
    Participant

    Must have been something about my cut and paste activity. I tried doing it from the admin (Appearance > Editor) and that’s where I got the message that I forwarded to you.

    I then also tried applying your snippet to the functions.php file in the child theme using FTP. That didn’t fix it either. I wonder if copying it from the webpage on this thread had anything to do with it. Strange…

    Oh well. Thanks for the support!

    #105474

    Artem Temos
    Keymaster

    You are welcome!

Viewing 10 posts - 1 through 10 (of 10 total)