De eerste stuk controleert of er subcategorieen zijn, zo ja dan worden deze getoond met de titel. De functie om te controleren of er subcategorieen is de eerste functie.
In functions.php
function has_term_have_children( $term_id = '', $taxonomy = 'category' )
{
// Check if we have a term value, if not, return false
if ( !$term_id )
return false;
// Get term children
$term_children = get_term_children( filter_var( $term_id, FILTER_VALIDATE_INT ), filter_var( $taxonomy, FILTER_SANITIZE_STRING ) );
// Return false if we have an empty array or WP_Error object
if ( empty( $term_children ) || is_wp_error( $term_children ) )
return false;
return true;
}
function woocommerce_product_category( $args = array() ) {
$woocommerce_category_id = get_queried_object_id();
$current_category = single_cat_title("", false);
if ( has_term_have_children( $woocommerce_category_id, 'product_cat' ) ):
echo '<h4>Meer voor jouw <strong>'.$current_category.'</strong></h4>';
echo '<div class="cats">';
echo do_shortcode('[product_categories columns="4" number="8" orderby="menu_order" parent="'.$woocommerce_category_id.'"]');
echo '</div>';
endif;
}
add_action( 'woocommerce_after_shop_loop', 'woocommerce_product_category', 100 );
#categorieen #children #functions #shortcode #subcategorieen #woocommerce