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.