Mostrar sólo los productos de la última categoría de WooCommerce en la sección de relacionados

WordPress

Si quieres mostrar sólo los productos de la última categoría dentro de tu sección de productos relacionados de WooCommerce, entonces coloca el siguiente código en tus funciones.php.add_filter( ‘woocommerce_get_related_product_cat_terms’, ‘last_child_cats_only’, 10, 2 );function last_child_cats_only( $term_ids, $product ) {si(!$producto) {devolver $term_ids;} $cats_array=array(); $terms=wp_get_post_terms($producto, ‘product_cat’); foreach ( $terms as $key => $term ){ $check_for_children=get_categories(array(‘parent’ => $term->term_id, ‘taxonomy’ => ‘product_cat’)); si(empty($check_for_children)){ $cats_array[]=$term->term_id; } } si(!empty($cats_array)) { $term_ids=$cats_array; } devolver $term_ids;}

Deja una respuesta

Tu dirección de correo electrónico no será publicada.

We use cookies to give you the best online experience. By agreeing you accept the use of cookies in accordance with our cookie policy.

Privacy Settings saved!
Privacy Settings

When you visit any web site, it may store or retrieve information on your browser, mostly in the form of cookies. Control your personal Cookie Services here.

These cookies are necessary for the website to function and cannot be switched off in our systems.

In order to use this website we use the following technically required cookies
  • wordpress_test_cookie
  • wordpress_logged_in_
  • wordpress_sec

Decline all Services
Accept all Services