Created
July 8, 2014 12:08
-
-
Save bluvertigo/0df9367f28480ef457bf to your computer and use it in GitHub Desktop.
Shortcode - Lista categorie partendo da categoria padre
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment