• Resolved maurosp91

    (@maurosp91)


    Hi there, I am trying to customize the vendor single store page. I need to show 2 products per cathegory + a “see more” link to see all the products for the picked cathegory.

    I’m not an expert doing these mods but learning.
    The way I’m trying to achieve it, is by modifying the WP query when the single store php file is called.

    The problem is that I can’t find where this query is triggered.
    Any help with this? Am I going in the right direction or is there a better way to do it?

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Tanvir Hasan

    (@tanvirh)

    Hi @maurosp91

    If you want to display two products per category and after that, you want to add a “see more” button on the single store page then this will require proper advanced customization from the Dokan codebase.

    According to our?support policy, we are unable to share any custom solution to our users currently.

    In this case, we recommend to hiring a professional WordPress developer to assist you in achieving such requirements.

    Hope the information will help.


    Thanks!

    Thread Starter maurosp91

    (@maurosp91)

    Hi, I could achieve it. I share the code in case someone finds it helpful.

    Firstly, I am using rehub theme. In which I modified 2 templates files in the child theme.

    • rehub-theme -> dokan -> store.php
    • rehub-theme -> inc -> parts -> woolistcompact.php (I’m using wholesale list as design of woo archive)

    If your theme doesn’t modify the dokan single store page, you only need to modify this file: dokan-lite -> templates -> store.php

    store.php: add these lines right before THE LOOP

    <?php
    
        //I get the URL of the current page to compare it with the vendor URL page
    
        $protocol = "https://";  
    
        $CurPageURL = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];  
    
    ?>

    woolistcompact.php: add these lines inside THE LOOP, right after checking if $product is not empty

    <?php
    
    //if current URL page is same as vendor URL page, then show 1 item per category
    
    if ( $CurPageURL == $store_url) {
    
        //get the categories of the product in each loop
    
        $cat_ids   = $product->get_category_ids();
    
        //if there is only 1 category
    
        if ( count($cat_ids) == 1 ) {
    
            $cat_id   = $cat_ids[0];
    
        } //if there are 2 categories, I take the child one
    
        elseif ( count($cat_ids) == 2 ) {
    
            $parents1 = get_ancestors( $cat_ids[0], 'product_cat', 'taxonomy' );
    
            $parents2 = get_ancestors( $cat_ids[1], 'product_cat', 'taxonomy' );
    
            if ( count($parents1) > count($parents2) ) {
    
                $cat_id = $cat_ids[0];
    
            } else {
    
                $cat_id = $cat_ids[1];
    
            }
    
        } //if there are 3 categories, I take the grandchild one
    
        elseif ( count($cat_ids) == 3 ) {
    
            $parents1 = get_ancestors( $cat_ids[0], 'product_cat', 'taxonomy' );
    
            $parents2 = get_ancestors( $cat_ids[1], 'product_cat', 'taxonomy' );
    
            $parents3 = get_ancestors( $cat_ids[2], 'product_cat', 'taxonomy' );
    
            if ( count($parents1) > count($parents2) ) {
    
                if ( count($parents1) > count($parents3) ) {
    
                    $cat_id = $cat_ids[0];
    
                } else {
    
                    $cat_id = $cat_ids[2];
    
                }
    
            } else {
    
                if ( count($parents2) > count($parents3) ) {
    
                    $cat_id = $cat_ids[1];
    
                } else {
    
                    $cat_id = $cat_ids[2];
    
                }
    
            }
    
        }
    
        //Get the category name
    
        $term = get_term_by( 'id', $cat_id, 'product_cat' );
    
        $cat_name = $term->name;
    
        //Checking if another item of the same category was already shown
    
        if ( $categories[$cat_id] == 1 ) {
    
            //was shown
    
            return;
    
        } else {
    
            //wasn't shown - FLAG
    
            $categories[$cat_id] = 1;
    
        }
    
    }
    
    ?>

    woolistcompact.php: add these lines right at the end of each loop

    <?php
    
    //Adding the "See more" link
    //Only when this happens
    if ( $CurPageURL == $store_url ) {
    
        ?>
    
           <div class="woocommerce type-product woocompactlist mb10 mt10 border-grey-bottom pb10">
    
                <b><h4  style="text-align:center;" class="mb5 mt5 fontbold lineheight10">
    
                <a href="<?php echo esc_url($store_url . '/section' . '/' . $cat_id);?>">          
    
                    <?php echo strtoupper($cat_name) . " - Ver más \u{27a1}"; ?>
    
                </a></h4></b>
    
           </div>
    
        <?php
    
    }
    
    ?>

    And the result:

    Main vendor’s product page: https://ibb.co/SywLCYH

    Other vendor’s product pages (filtered by categories, search, etc): https://ibb.co/BnQfDDn (everything stays the same)

    As I said before, I’m learning, so this might not be the best solution, but is very functional (:

    • This reply was modified 1 year, 9 months ago by maurosp91.
    Plugin Support Tanvir Hasan

    (@tanvirh)

    Hi @maurosp91

    Thanks for sharing. We are glad to know that you have found the solution on your own and we really appreciate that. I believe the solution will help others who are looking for similar functionality.

    However, as the purpose of this topic has been served we are marking this as resolved. Feel free to open a new one for any further issues or queries.

    Cheers!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Modify WP query for vendor single store page’ is closed to new replies.