Home Forums WoodMart support forum Swatches not showing on shop/search results

Swatches not showing on shop/search results

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

    ruandeyzel
    Participant

    Please have a look on https://legwearsafari.co.za/staging and search for “Falke High School Opaques” – some swatches are missing, but does appear to be there when going into the single product.

    #34868

    Eric Watson
    Participant

    Hello,

    Could you please provide us your admin so we can check what is wrong there?

    Kind Regards
    XTemos Studio

    #34884

    ruandeyzel
    Participant

    Here you go

    #34921

    Artem Temos
    Keymaster

    Please, provide us your FTP access also.

    #34927

    ruandeyzel
    Participant

    FTP

    #34953

    Artem Temos
    Keymaster

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

    function woodmart_swatches_list( $attribute_name = false ) {
    		global $product;
    
    		$id = $product->get_id();
    
    		if( empty( $id ) || ! $product->is_type( 'variable' ) ) return false;
    
    		$available_variations = $product->get_available_variations();
    
    		if( ! $attribute_name ) {
    			$attribute_name = woodmart_grid_swatches_attribute();
    		}
    
    		if( empty( $available_variations ) ) return false;
    
    		$swatches_to_show = woodmart_get_option_variations(  $attribute_name, $available_variations, false, $id );
    
    		if( empty( $swatches_to_show ) ) return false;
    		$out = '';
    
    		$out .=  '<div class="swatches-on-grid">';
    
    		$swatch_size = woodmart_wc_get_attribute_term( $attribute_name, 'swatch_size' );
    
    		if( apply_filters( 'woodmart_swatches_on_grid_right_order', true ) ) {
    			$terms = wc_get_product_terms( $product->get_id(), $attribute_name, array( 'fields' => 'slugs' ) );
    			
    			$swatches_to_show_tmp = $swatches_to_show;
    
    			$swatches_to_show = array();
    
    			foreach ($terms as $id => $slug) {
    				$swatches_to_show[$slug] = $swatches_to_show_tmp[$slug];
    			}
    		}
    		$swatches_to_show = array_filter( $swatches_to_show, function($value) { return $value !== ''; });
    		
    
    		foreach ($swatches_to_show as $key => $swatch) {
    			$style = $class = '';
    			
    			if ( empty( $swatch ) ) continue;
    
    			if( ! empty( $swatch['color'] )) {
    				$style = 'background-color:' .  $swatch['color'];
    			} else if( ! empty( $swatch['image'] ) ) {
    				$style = 'background-image: url(' . $swatch['image'] . ')';
    			} else if( ! empty( $swatch['not_dropdown'] ) ) {
    				$class .= 'text-only ';
    			}
    
    			$style .= ';';
    
    			$data = '';
    
    			if( isset( $swatch['image_src'] ) ) {
    				$class .= 'swatch-has-image';
    				$data .= 'data-image-src="' . $swatch['image_src'] . '"';
    				$data .= ' data-image-srcset="' . $swatch['image_srcset'] . '"';
    				$data .= ' data-image-sizes="' . $swatch['image_sizes'] . '"';
    				if( woodmart_get_opt( 'swatches_use_variation_images' ) ) {
    					$thumb = wp_get_attachment_image_src( get_post_thumbnail_id( $swatch['variation_id'] ), 'shop_thumbnail');
    					if ( !empty( $thumb ) ) {
    						$style = 'background-image: url(' . $thumb[0] . ')';
    						$class .= ' variation-image-used';
    					}
    				}
    
    				if( ! $swatch['is_in_stock'] ) {
    					$class .= ' variation-out-of-stock';
    				}
    			}
    
    			$class .= ' swatch-size-' . $swatch_size;
    
    			$term = get_term_by( 'slug', $key, $attribute_name );
    
    			$out .=  '<div class="swatch-on-grid woodmart-tooltip ' . esc_attr( $class ) . '" style="' . esc_attr( $style ) .'" ' . $data . '>' . $term->name . '</div>';
    		}
    
    		$out .=  '</div>';
    
    		return $out;
    
    	}
    #34974

    ruandeyzel
    Participant

    Will this fix also be in the next update?

    #34978

    Artem Temos
    Keymaster

    Yes, we will include it in the next update.

    #34995

    ruandeyzel
    Participant

    Awesome thanks for the help

    #34996

    Artem Temos
    Keymaster

    You are welcome!

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