Guest User

Untitled

a guest
Mar 22nd, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1. <?php
  2. /**
  3. * Show Categories menu
  4. *
  5. */
  6. $seller_id = (int) get_query_var('author');
  7. ?>
  8. <aside class="cat-menu">
  9. <h3 class="cat-menu-title"><?php echo "Catégories"; ?></h3>
  10. <div id="cat-drop-stack">
  11. <?php
  12.  
  13. global $wpdb;
  14.  
  15. $sql = "SELECT t.term_id,t.name, tt.parent FROM $wpdb->terms as t
  16. LEFT JOIN $wpdb->term_taxonomy as tt on t.term_id = tt.term_id
  17. LEFT JOIN $wpdb->term_relationships AS tr on tt.term_taxonomy_id = tr.term_taxonomy_id
  18. LEFT JOIN $wpdb->posts AS p on tr.object_id = p.ID
  19. WHERE tt.taxonomy = 'product_cat'
  20. AND p.post_type = 'product'
  21. AND p.post_status = 'publish'
  22. AND p.post_author = $seller_id GROUP BY t.term_id";
  23.  
  24. $categories = $wpdb->get_results( $sql );
  25. //var_dump($categories);
  26.  
  27. $walker = new Dokan_Store_Category_Walker( $seller_id );
  28. echo "<ul style="width:250px;height:400px;overflow: scroll;">";
  29. echo call_user_func_array( array(&$walker, 'walk'), array($categories, 0, array()) );
  30. echo "</ul>";
  31. ?>
  32. </div>
  33. </aside>
  34. <script>
  35. ( function ( $ ) {
  36. $( '#cat-drop-stack li.has-children' ).on( 'click', '> a span.caret-icon', function ( e ) {
  37. e.preventDefault();
  38. var self = $( this ),
  39. liHasChildren = self.closest( 'li.has-children' );
  40.  
  41. if ( !liHasChildren.find( '> ul.children' ).is( ':visible' ) ) {
  42. self.find( 'i.fa' ).addClass( 'fa-rotate-90' );
  43. if ( liHasChildren.find( '> ul.children' ).hasClass( 'level-0' ) ) {
  44. self.closest( 'a' ).css( { 'borderBottom': 'none' } );
  45. }
  46. }
  47.  
  48. liHasChildren.find( '> ul.children' ).slideToggle( 'fast', function () {
  49. if ( !$( this ).is( ':visible' ) ) {
  50. self.find( 'i.fa' ).removeClass( 'fa-rotate-90' );
  51.  
  52. if ( liHasChildren.find( '> ul.children' ).hasClass( 'level-0' ) ) {
  53. self.closest( 'a' ).css( { 'borderBottom': '1px solid #eee' } );
  54. }
  55. }
  56. } );
  57. } );
  58. } )( jQuery );
  59. </script>
  60. <?php
  61.  
  62. function __construct( $seller_id ) {
  63. $this->store_url = dokan_get_store_url ( $seller_id );
  64. }
  65.  
  66. function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
  67. extract( $args );
  68. $indent = str_repeat( "t", $depth );
  69.  
  70. $url = $this->store_url . 'section/' . $category->term_id;
  71. $selected_cat = get_query_var( 'term' );
  72. $a_selected_class = $selected_cat == $category->term_id ? 'class="selected"' : '';
  73.  
  74. if ( $depth == 0 ) {
  75. $caret = $args['has_children'] ? ' <span class="caret-icon"><i class="fa fa-angle-right" aria-hidden="true"></i></span>' : '';
  76. $class_name = $args['has_children'] ? ' class="has-children parent-cat-wrap"' : ' class="parent-cat-wrap"';
  77. $output .= $indent . '<li' . $class_name . '>' . "nt" .'<a href="' . $url . '"'. $a_selected_class .'>' . $category->name . $caret . '</a>' . "n";
  78. } else {
  79. $caret = $args['has_children'] ? ' <span class="caret-icon"><i class="fa fa-angle-right" aria-hidden="true"></i></span>' : '';
  80. $class_name = $args['has_children'] ? ' class="has-children"' : '';
  81. $output .= $indent . '<li' . $class_name . '><a href="' . $url . '"'.$a_selected_class.'>' . $category->name . $caret . '</a>';
  82. }
  83. }
Add Comment
Please, Sign In to add comment