2017-01-15 71 views
0

我試圖創建一個函數,其中所有可用的顏色(屬性/術語)被附加到每個產品 - 在類別頁面(產品列表)上。下面的代碼有效,但是,前端順序與後端順序不同。我真的無法弄清楚,我想如何獲得相應排序的屬性。已嘗試將menu_order更改爲term_order。這也算不了什麼。通過全球/後端訂單(orderby)訂購WordPress的屬性

function ea_display_color_swatches_on_category() { 
    $html_swatch = '<div class="swatches-wrapper">'; 

    $terms = wp_get_object_terms(get_the_ID(), 'pa_farve', array('orderby' => 'menu_order')); 

    foreach ($terms as $term) { 
     $hex_color = get_woocommerce_term_meta($term->term_id, 'pa_farve_swatches_id_color', true); 

     $html_swatch .= '<a class="swatch-color-category tooltips" 
      title="' . $term->name . '" 
      style="background:' . $hex_color . '" ></a>'; 
    } 

    // end color-swatches-wrapper 
    $html_swatch .= '</div>'; 

    echo $html_swatch; 


} 
add_action('woocommerce_before_shop_loop_item', 'ea_display_color_swatches_on_category'); 

enter image description here

enter image description here

Source

回答

0

您是否嘗試過與term_id? WordPress使用按創建日期排序。