'product_cat', 'hide_empty' => false, 'parent' => 0, ) ); echo '
'; echo '
'; echo '
Select product categories
'; echo '
'; if ( ! is_wp_error( $parent_categories ) && ! empty( $parent_categories ) ) { foreach ( $parent_categories as $parent ) { $checked = in_array( $parent->term_id, $selected_cats ) ? 'checked' : ''; echo ''; // Get children of this parent $children = get_terms( array( 'taxonomy' => 'product_cat', 'hide_empty' => false, 'parent' => $parent->term_id, ) ); if ( ! is_wp_error( $children ) && ! empty( $children ) ) { foreach ( $children as $child ) { $checked = in_array( $child->term_id, $selected_cats ) ? 'checked' : ''; echo ''; } } } } echo '
'; ?>