Skip to content

Instantly share code, notes, and snippets.

@saimonh3
Created March 22, 2019 03:55
Show Gist options
  • Save saimonh3/80be0cc512dec933a821c8bf305cec54 to your computer and use it in GitHub Desktop.
Save saimonh3/80be0cc512dec933a821c8bf305cec54 to your computer and use it in GitHub Desktop.
function dokan_store_category_menu( $seller_id, $title = '' ) {
?>
<div id="cat-drop-stack">
<?php
$vendor = dokan()->vendor->get( get_query_var( 'author' ) );
$vendor_id = $vendor->get_id();
$products = $vendor->get_products();
$product_ids = [];
foreach ( $products->posts as $product ) {
array_push( $product_ids, $product->ID );
}
// hold all the terms
$all_terms = [];
foreach ( $product_ids as $product_id ) {
$terms = get_the_terms( $product_id, 'product_cat' );
array_push( $all_terms, $terms[0] );
}
// hold unique categoreis
$categories = [];
foreach ( $all_terms as $term ) {
$categories[ serialize( $term ) ] = $term;
}
$categories = array_values( $categories );
$walker = new Dokan_Store_Category_Walker( $seller_id );
echo "<ul>";
echo call_user_func_array( array( &$walker, 'walk' ), array( $categories, 0, array() ) ); //phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped
echo "</ul>";
?>
</div>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment