2017-07-24 5 views
0

Ich benutze das Plugin WooCommerce Variation Swatches und Fotos, die ich ein Miniaturbild zu den Eigenschaften meines Produkts hinzufügen kann.WooCommerce erhalten Attribut thumbnail - Variation Farbfelder und Fotos plugin

Ich muss alle Attribute auf einer Vorlage auflisten und ich möchte auch die Miniaturansicht erhalten und anzeigen.

$terms = get_terms(array(
    'taxonomy' => 'pa_texture', 
    'hide_empty' => false, 
)); 
foreach ($terms as $term) { 
    print_r($term); 
} 

Die Thumbnail-Funktion in WooCommerce Standard ist nicht so, wenn ich $ TERM gibt print_r keine Thumbnail-URL:

WP_Term Object 
(
    [term_id] => 54 
    [name] => Guilin 
    [slug] => guilin 
    [term_group] => 0 
    [term_taxonomy_id] => 54 
    [taxonomy] => pa_texture 
    [description] => Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla imperdiet facilisis convallis. 
    [parent] => 0 
    [count] => 2 
    [filter] => raw 
    [meta_value] => 0 
) 

Wie kann ich die Miniaturansicht des Attributs bekommen?

Antwort

1

Die Lösung gefunden dank @ Und3rTow's Eingabe. Der richtige Parameter in get_woocommerce_term_meta ist pa_texture_swatches_id_photo.

Hier ist der endgültige Code:

$thumbnail_id = get_woocommerce_term_meta($term->term_id, 'pa_texture_swatches_id_photo', true); 
$textureImg = wp_get_attachment_image_src($thumbnail_id); ?> 
<img src="<?php echo $textureImg[0]; ?>"> 
1

Der klassische Weg für Produktkategorien Begriffe 'product_cat' Taxonomie ist:

$terms = get_terms(array(
    'taxonomy' => 'product_cat', 
    'hide_empty' => false, 
)); 

foreach ($terms as $term) { 
    $thumb_id = get_woocommerce_term_meta($term->term_id, 'thumbnail_id', true); 
    $img_src = wp_get_attachment_url( $thumb_id); 
    echo '<p><img src="'.$img_src.'" alt="" />'.$tem->name.'</p>'; 
} 

So zum Produkt der Taxonomie Attribute wie 'pa_texture' werden kann ändern, sollte es den Trick
(ich hoffe, , aber ich bin nicht sicher,, da ich nicht Variation Swatches und Fotos Plugin).

+0

Danke, aber das hat nicht funktioniert :( – Jeff

1

Diese ungetestet ist jedoch eine gewisse Variation der folgenden sollte funktionieren:

foreach ($terms as $key => $term) { 
    $thumbnail_id = get_woocommerce_term_meta($term->term_id, $term->taxonomy . '_photo', true); 
    $terms[ $key ]->thumb = wp_get_attachment_image_src($thumbnail_id); 
    print_r($term); 
} 

Wenn man sich the relevant plugin file anschaut, kann man sehen, wie der Autor die Bilder bekommen. Der obige Code basiert darauf.

+0

Danke Ich denke, das die richtige Richtung ist, aber das tat es nicht Ich versuche, es wieder gut zu machen, aber noch kein Glück :( – Jeff

0

Ich hatte ein ähnliches Problem, wenn Bilder in upsells Produkte angezeigt werden. Es ist ein Chaos, aber:

if ($products_upsells->have_posts()) : while ($products_upsells->have_posts()) : $products_upsells->the_post(); 
     $_product = wc_get_product(get_the_ID()); 
     $attributes = $_product->get_attributes(); 
     $attr_id = $attributes['pa_kolor']['options'][0]; 
     $thumb_id = get_term_meta($attr_id); 
     $img_src = wp_get_attachment_url($thumb_id['pa_kolor_swatches_id_photo'][0]); 
     echo '<img src="'.$img_src.'" alt="" />'; 
    endwhile; endif; 
    wp_reset_query(); 

diesen Code Siehe:

$_product = wc_get_product(get_the_ID()); 
$attributes = $_product->get_attributes(); 
$attr_id = $attributes['pa_kolor']['options'][0]; 
$thumb_id = get_term_meta($attr_id); 
$img_src = wp_get_attachment_url($thumb_id['pa_kolor_swatches_id_photo'][0]); 
Verwandte Themen