You should add 'child_of' => 0,
That way you will display only Main categories aka children of 0.
$custom_args = array(
'orderby' => 'name',
'order' => 'ASC',
'child_of' => 0,
'depth' => 1,
'number' => 4,
);
wp_list_categories($custom_args);
If you want to get WooCommerce categories try this:
function getCustomProductCats () {
$orderby = 'name';
$order="asc";
$hide_empty = false ;
$cat_args = array(
'orderby' => $orderby,
'order' => $order,
'child_of' => 0,
'number' => 4,
'hide_empty' => $hide_empty,
);
$product_categories = get_terms( 'product_cat', $cat_args );
if( !empty($product_categories) ){
echo '<ul>';
foreach ($product_categories as $key => $category) {
echo '<li>';
echo '<a href="'.get_term_link($category).'" >';
echo $category->name;
echo '</a>';
echo '</li>';
}
echo '</ul>';
}
}
getCustomProductCats();
source for WC solution https://phptechnologytutorials.wordpress.com/2018/03/10/get-list-of-all-product-categories-in-woocommerce/