bluvertigo
7/8/2014 - 12:08 PM

Shortcode - Lista categorie partendo da categoria padre

Shortcode - Lista categorie partendo da categoria padre

/* Woocommerce - Lista Categorie */

function woocommerce_subcats_from_parentcat_by_name($parent_cat_NAME) {
  $IDbyNAME = get_term_by('slug', $parent_cat_NAME, 'product_cat');
  $product_cat_ID = $IDbyNAME->term_id;
    $args = array(
       'hierarchical' => 1,
       'show_option_none' => '',
       'hide_empty' => 0,
       'parent' => $product_cat_ID,
       'taxonomy' => 'product_cat'
    );
  $subcats = get_categories($args);
    echo '<ul class="wooc_sclist">';
      foreach ($subcats as $sc) {
        $link = get_term_link( $sc->slug, $sc->taxonomy );
          echo '<li><a href="'. $link .'">'.$sc->name.'</a></li>';
      }
    echo '</ul>';
}

// Add Shortcode
function lista_categorie( $atts ) {

	// Attributes
	$attr = shortcode_atts(
		array(
			'parent' => '',
		), $atts );

	// Code
	woocommerce_subcats_from_parentcat_by_name($atts['parent']);

}
add_shortcode( 'categorie_prodotti', 'lista_categorie' );