@sidaka

Как отобразить один атрибут на странице корзины?

Привет, нашел код для этой задачи но почему то он не отображает атрибуты которые я только что создал. А вот старые отображает. Товар вместе с атрибутами добавлялись через импорт , может в этом дело? Не пойму откуда копать начать.
Код ниже, для добавления конкретного атрибута меняю attribute_name на нужный мне (например pa_kozi) и атрибут видно в корзине, но любой вновь созданный атрибут отображаться не хочет :(
Подскажите плз

64a4366e84476846878688.png

function isa_woo_cart_attribute_values( $cart_item, $cart_item_key ) {

$item_data = $cart_item_key['data'];
$attributes = $item_data->get_attributes();
  
if ( ! $attributes ) {
    return $cart_item;
}
  
$out = $cart_item . '<br />';
  
$count = count( $attributes );
  
$i = 0;
foreach ( $attributes as $attribute ) {

    // skip variations
    if ( $attribute->get_variation() ) {
         continue;
    }

    $name = $attribute->get_name();          
    if ( $attribute->is_taxonomy() ) {

        if ($name !== 'attribute_name') {
            continue;
        }

        $product_id = $item_data->get_id();
        $terms = wp_get_post_terms( $product_id, $name, 'all' );
           
        // get the taxonomy
        $tax = $terms[0]->taxonomy;
           
        // get the tax object
        $tax_object = get_taxonomy($tax);
           
        // get tax label
        if ( isset ( $tax_object->labels->singular_name ) ) {
            $tax_label = $tax_object->labels->singular_name;
        } elseif ( isset( $tax_object->label ) ) {
            $tax_label = $tax_object->label;
            // Trim label prefix since WC 3.0
            $label_prefix = 'Product ';
            if ( 0 === strpos( $tax_label,  $label_prefix ) ) {
                $tax_label = substr( $tax_label, strlen( $label_prefix ) );
            }
        }
        $out .= $tax_label . ': ';

        $tax_terms = array();              
        foreach ( $terms as $term ) {
            $single_term = esc_html( $term->name );
            array_push( $tax_terms, $single_term );
        }
        $out .= implode(', ', $tax_terms);
          
        if ( $count > 1 && ( $i < ($count - 1) ) ) {
            $out .= ', ';
        }
      
        $i++;
        // end for taxonomies
  
    } else {

        // not a taxonomy
          
        $out .= $name . ': ';
        $out .= esc_html( implode( ', ', $attribute->get_options() ) );
      
        if ( $count > 1 && ( $i < ($count - 1) ) ) {
            $out .= ', ';
        }
      
        $i++;
          
    }
}
echo $out;

}
add_filter( 'woocommerce_cart_item_name', isa_woo_cart_attribute_values, 10, 2 );
  • Вопрос задан
  • 27 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы