2014-10-01 80 views
0

當我嘗試添加子類別時,它們在頁面刷新後消失。我可以添加產品給他們,但他們不顯示在前端和後端。無法添加子類別Woocommerce

任何想法?

我已經在Woocommerce設置中「清除瞬態」和「重新計算條件」。兩者都沒有運氣。

回答

0

您必須添加此代碼來提交您的WordPress主題的functions.php:

//Добавляем Подкатегории В Постоянные Ссылки В Woocommerce 
remove_filter('post_type_link', 'woocommerce_product_cat_filter_post_link', 10, 2); // для версии woocommerce ниже 2.0 
remove_filter('post_type_link', 'wc_product_post_type_link', 10, 2); // для версии woocommerce >= 2 
add_filter('post_type_link', 'woocommerce_subcategory_permalink', 10, 2); 
function woocommerce_subcategory_permalink($permalink, $post) { 

    // Прекращаем работу, если запись не является товаром 
    if ($post->post_type !== 'product') 
     return $permalink; 

    // Прекращаем работу, если тег перезаписи местоположения не находится в генерируемой ссылке 
    if (false === strpos($permalink, '%product_cat%')) 
     return $permalink; 

    // Получаем пользовательскую таксономию, используемую этой записью 
    $terms = get_the_terms($post->ID, 'product_cat'); 

    if (empty($terms)) { 
     $permalink = str_replace('%product_cat%', _x('product', 'slug', 'woocommerce'), $permalink); 
    } else { 
     $first_term = array_shift($terms); 

     // Получаем иерархическую product_category 
     $parents = woo_get_term_parents($first_term->term_id, 'product_cat'); 

     $permalink = str_replace('%product_cat%/', $parents, $permalink); 
    } 

    return $permalink; 
} 

if (! function_exists('woo_get_term_parents')) { 
    function woo_get_term_parents($id, $taxonomy) { 
     $chain = ''; 
     $parent = &get_term($id, $taxonomy); 
     if (is_wp_error($parent)) 
      return $parent; 

     $name = $parent->slug; 

     if ($parent->parent && ($parent->parent != $parent->term_id) ) { 
      $chain .= woo_get_term_parents($parent->parent, $taxonomy); 
     } 

     $chain .= $name."/"; 
     return $chain; 
    } // End woo_get_term_parents() 
} 
相關問題