Site logo

Archived topic

Hide cart in menu for a specific user role

32 replies · Started by Deyson on April 18, 2022

Viewing posts 1–15 of 33

Hello and good day.

I sell digital downloads as well as yearly subscriptions.
When an active member is logged in they have the user role "Active Subscriber" and they have instant access to all the digital downloads.

Is there a way to hide the small cart icon in the Niche top main menu as they do not need to go through checkout?

Please let me know what you think. 🤔
Thank you and have an amazing day! 😊

Hi there,

according to the Woo filter reference theres a wcs_user_has_subscription filter for setting subscription status which having a nose around led me to this method to check if a user has an active sub:

$has_sub = wcs_user_has_subscription( '', '', 'active' );

Which we can use ina GPP option_generate_woocommerce_settings filter to set some parameters using this snippet:

add_filter( 'option_generate_woocommerce_settings','hide_menu_cart_if_active_sub' );
function hide_menu_cart_if_active_sub( $options ) {
    $has_sub = wcs_user_has_subscription( '', '', 'active' );

    if ( $has_sub ) {
        $options[‘cart_menu_item’] = false;
    }
    
    return $options;
}

Thank you, very much! 😊

Do you happen to know how to redirect the Minu Cart to the Checkout and not the cart page?

Thank you and have an amazing day! 😊

Hmmm.... to change the cart link would mean replacing the entire function. Are you not using the Cart Sub Menu ? As that has a link to the Checkout

The cart submenu stopped working and I could not figure out why. :(

Hi Deyson,

Can you check customizer > layout > woocommerce > general, if the Display mini cart sub-menu is ticked?

Let me know!

It is checked. 😊

Thank you and have an amazing day! 😊

I am sorry, I had meant it is Ticked. 😊

It looks like the cart function has some issue, the sub menu doesn't load.

Are you using any custom functions related to the cart?

Let me know!

Hello,
I added disabled cart fragments, which may be the cause.
From what I understand this helps lower load time on my website.

add_action( 'wp_print_scripts', 'de_script', 100 );

function de_script() {
    wp_dequeue_script( 'wc-cart-fragments' );

    return true;
}

Please let me know what you think. 🤔

The Cart Menu relies on the wc-cart-fragments script.
If you want to see the cart menu you will need to remove that snippet.

From what I understand this helps lower load time on my website.

It simply disables a script that on very busy sites ( and maybe slower servers ) can cause delays.
You can always re-enable it, and if you notice a significant slow down ask your host if that script is the problem.

Thank you David.

My website host has a Caching system. But, a page's cache creation is triggered only after someone visits that page.
The page's cache is not automatically created. It is only created after the first initial visit.

So my goal is to try to shave off as much time as possible for those that see the page when it is uncached. Hence why I ran the script above.

Do you have any advice on what I should do?

Thank you and have an amazing day! 😊

If you really want to take advantage of Page Caching then you will need to keep the snippet to remove the fragments and do without the Cart Sub Menu.

Thank you.
Also is it possible to have the mini cart icon redirect to the checkout instead of the cart page?

Thank you and have an amazing day! 😊

Is it only that icon that will go straight to checkout ? or will all links to Cart go to Checkout ?

This archived topic is closed to new replies.