Color swatches issue

Hey all,

color swatches do not work properly when the title of the attribute is different from the slug. I've noticed this behavior with the colors if you have for example:

Attribute name (bg) | Slug (en)

Червен | red

Зелен | green

---

at that point

$atr = [[0] => 'Червен', [1] => 'Зелен']

 case 'color':
                  echo '<ul class="mfn-vr-options mfn-vr-color" data-atr="'.$atr_slug.'">';
                  foreach($atr as $item){
                     $atr_item = get_term_by('slug', $item, $atr_slug); //original code 
                     $atr_item = get_term_by('name', $item, $atr_slug); //fix
                     if(isset($atr_item->name)){
                        $mfn_value = get_term_meta($atr_item->term_id, 'mfn_attr_field', true);
                        //if( !isset($mfn_value) || empty($mfn_value) || ( isset($mfn_value) && strpos('#', $mfn_value) === false ) ) $mfn_value = ''; // no color
                        echo '<li class="tooltip tooltip-txt" data-tooltip="'.esc_html($atr_item->name).'"><a href="'.get_the_permalink($product->get_id()).'?'.$a.'='.$atr_item->slug.'" data-id="'.$atr_item->slug.'"><span style="background-color: '.$mfn_value.';"></span></a></li>';
                     }
                  }
                  echo '</ul>';
                  break;


I'm not sure if this is the correct way to fix it in general, you might want to handle it in a different way.

Cheers.

Comments

Sign In or Register to comment.