{"id":1099,"date":"2020-03-31T13:30:43","date_gmt":"2020-03-31T11:30:43","guid":{"rendered":"https:\/\/www.welaunch.io\/fr\/?p=1099"},"modified":"2024-05-15T11:38:07","modified_gmt":"2024-05-15T09:38:07","slug":"show-only-last-woocommerce-category-products-in-related-section","status":"publish","type":"post","link":"https:\/\/www.welaunch.io\/fr\/2020\/03\/show-only-last-woocommerce-category-products-in-related-section\/","title":{"rendered":"Afficher uniquement les produits de la derni\u00e8re cat\u00e9gorie de WooCommerce dans la section connexe"},"content":{"rendered":"<p>Si vous souhaitez afficher uniquement les produits de la derni\u00e8re cat\u00e9gorie dans votre section de produits apparent\u00e9s de WooCommerce, placez le code suivant dans vos fonctions.php.add_filter(&#8216;woocommerce_get_related_product_cat_terms&#8217;, &#8216;last_child_cats_only&#8217;, 10, 2 ) ;function last_child_cats_only( $term_ids, $product ) {si(!$product) {return $term_ids ;}    $cats_array=array() ;    $terms=wp_get_post_terms($product, &#8216;product_cat&#8217;) ;    foreach ( $terms as $key => $term ){        $check_for_children=get_categories(array(&#8216;parent&#8217; => $term->term_id, &#8216;taxonomy&#8217; => &#8216;product_cat&#8217;)) ;        si(empty($check_for_children)){            $cats_array[]=$term->term_id ;        }    }    si(!empty($cats_array)) {    $term_ids=$cats_array ;    }   return $term_ids ;}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Si vous souhaitez afficher uniquement les produits de la derni\u00e8re cat\u00e9gorie dans votre section de produits apparent\u00e9s de WooCommerce, placez le code suivant dans vos fonctions.php.add_filter(&#8216;woocommerce_get_related_product_cat_terms&#8217;, &#8216;last_child_cats_only&#8217;, 10, 2 ) ;function last_child_cats_only( $term_ids, $product ) {si(!$product) {return $term_ids ;} $cats_array=array() ; $terms=wp_get_post_terms($product, &#8216;product_cat&#8217;) ; foreach ( $terms as $key => $term ){ $check_for_children=get_categories(array(&#8216;parent&#8217; => $term->term_id,&#8230;<\/p>\n","protected":false},"author":1,"featured_media":2749,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-1099","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-woocommerce"],"_links":{"self":[{"href":"https:\/\/www.welaunch.io\/fr\/wp-json\/wp\/v2\/posts\/1099","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.welaunch.io\/fr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.welaunch.io\/fr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.welaunch.io\/fr\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.welaunch.io\/fr\/wp-json\/wp\/v2\/comments?post=1099"}],"version-history":[{"count":2,"href":"https:\/\/www.welaunch.io\/fr\/wp-json\/wp\/v2\/posts\/1099\/revisions"}],"predecessor-version":[{"id":8983,"href":"https:\/\/www.welaunch.io\/fr\/wp-json\/wp\/v2\/posts\/1099\/revisions\/8983"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.welaunch.io\/fr\/wp-json\/wp\/v2\/media\/2749"}],"wp:attachment":[{"href":"https:\/\/www.welaunch.io\/fr\/wp-json\/wp\/v2\/media?parent=1099"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.welaunch.io\/fr\/wp-json\/wp\/v2\/categories?post=1099"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.welaunch.io\/fr\/wp-json\/wp\/v2\/tags?post=1099"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}