I'm trying to show two archives, one for admins/shop managers another for the rest.
The issue is that I'm using a combination of blocks and legacy.
This is as far as I got and it semi-worked:
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<div class="mainLoopML">
<wpv-loop wrap="3" pad="true">
[wpv-conditional if=" NOT ( ( '[wpv-current-user info="role"]' eq 'administrator' ) OR ( '[wpv-current-user info="role"]' eq 'shop_manager' ) ) "]
[wpv-item index=1]
<div class="child">
[wpv-post-body view_template="76687"]
</div>
[wpv-item index=other]
<div class="child">
[wpv-post-body view_template="76687"]
</div>
[wpv-item index=3]
<div class="child">
[wpv-post-body view_template="76687"]
</div>
[/wpv-conditional]
[wpv-conditional if=" ( ( '[wpv-current-user info="role"]' eq 'administrator' ) OR ( '[wpv-current-user info="role"]' eq 'shop_manager' ) ) "]
[wpv-post-body view_template="70421"]
[/wpv-conditional]
</wpv-loop>
</div>
[wpv-pager-archive-nav-links output="bootstrap" first_last_links="true" previous_next_links="true" step="100" reach="4"]
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
[/wpv-no-items-found]
[wpv-layout-end]
Using only blocks I know I can do it since I'm already doing it for other things, but with this mix, basically the conditional display is the issue and I'm not sure how to solve.
I could just do the conditional display in the blocks (sure) but the issue there is that I want the layout to be different, for admins/shop managers I want the current layout which is a list-type product, that's 1 product per line, whereas for non-admins I want 3 products per line in a card-type style.
Thank you.
Hi,
Thank you for contacting us and I'd be happy to assist.
From the "semi-worked", do you mean that conditional statements are not working as expected or they're working, but you'd prefer an alternative where you don't have to use this combination of blocks and legacy?
You're also welcome to share temporary admin login details so that I can see how these different layouts are set up. I'll be in a better position to suggest some recommendations, accordingly.
Note: Your next reply will be private and making a complete backup copy is recommended before sharing the access details.
regards,
Waqar
Thank you for sharing these details.
I'll review your website's setup, perform some tests on my website, and then share the findings, accordingly.
Thank you for your patience.
Thank you for waiting.
During testing on my website, I was able to make the switching of the assigned archives work, by using the "wpv_filter_force_wordpress_archive" filter:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_force_wordpress_archive
To achieve this, you can create one archive, let's call it 'Archive A' that will be shown to everyone, and set it to be assigned to the desired items under the "Loop selection" settings.
Next, you can create another archive, let's call it 'Archive B', that will be shown to only 'administrator' and 'shop_manager' roles, but you'll not assign it to any item under the "Loop selection" settings.
After that, the custom function attached to the "wpv_filter_force_wordpress_archive" filter can check if the current user is either 'administrator' or 'shop_manager' and if the condition is true, change the assigned archive to "Archive B", for that user only:
add_filter( 'wpv_filter_force_wordpress_archive', 'custom_archive_switch_func', 30, 2 );
function custom_archive_switch_func( $wpa_assigned, $wpa_loop ) {
// currently assigned archive
$wpa_to_apply = $wpa_assigned;
// if visitor is logged in
if( is_user_logged_in() ) {
// get current user's role
$user = wp_get_current_user();
$roles = ( array ) $user->roles;
//if user has 'administrator' or 'shop_manager' role
if ( (in_array('administrator', $roles)) || (in_array('shop_manager', $roles)) ) {
// set a different archive
$wpa_to_apply = '12345';
}
}
return $wpa_to_apply;
}
Note: Please replace '12345' with the actual archive ID that you've created for the 'administrator' or 'shop_manager' roles.
The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.