
-
AuthorPosts
-
November 4, 2015 at 8:29 pm #530393
Hi everyone,
I need to hide the cart dropdown for non logged users and show it only for specific user roles?
is there a workaround or snippet for this?Kind Regards,
ChrisNovember 5, 2015 at 9:56 am #530626Hi chris1986!
Thank you for using Enfold.
Add this in the functions.php file:
add_action( 'init', 'avia_woocommerce_cart_placement', 10); function avia_woocommerce_cart_placement() { $position = avia_get_option('header_position', 'header_top') == "header_top" ? "ava_main_header" : "ava_inside_main_menu"; if(avia_get_option('cart_icon') == "always_display_menu") { $position = "ava_inside_main_menu"; if( strpos( avia_get_option('header_layout'), 'bottom_nav_header') !== false && avia_get_option('header_position') == 'header_top') { $position = "ava_before_bottom_main_menu"; } } if ( is_user_logged_in() ) { add_action( $position, 'avia_woocommerce_cart_dropdown', 10); } }
If you want to display the cart for specific user role change the conditional function is_user_logged_in() to current_user_can(): https://codex.wordpress.org/Function_Reference/current_user_can
Cheers!
IsmaelNovember 5, 2015 at 11:06 am #530656Made my day!
Thanks a lot Ismael =) it works .For everyone who needs to setup the cart with more than one role:
add_action( ‘init’, ‘avia_woocommerce_cart_placement’, 10);
function avia_woocommerce_cart_placement()
{
$position = avia_get_option(‘header_position’, ‘header_top’) == “header_top” ? “ava_main_header” : “ava_inside_main_menu”;
if(avia_get_option(‘cart_icon’) == “always_display_menu”)
{
$position = “ava_inside_main_menu”;
if( strpos( avia_get_option(‘header_layout’), ‘bottom_nav_header’) !== false && avia_get_option(‘header_position’) == ‘header_top’)
{
$position = “ava_before_bottom_main_menu”;
}
}$user = wp_get_current_user();
$allowed_roles = array(‘your_custom_role1’, ‘your_custom_role2’, ‘your_custom_role3’);
if( array_intersect($allowed_roles, $user->roles ) ) {add_action( $position, ‘avia_woocommerce_cart_dropdown’, 10);}
}Have a nice day.
Kind Regards,
ChrisNovember 6, 2015 at 4:51 am #531326 -
AuthorPosts
- You must be logged in to reply to this topic.