Site logo

[Support request] Hide cart in menu for a specific user role

Home Forums Support [Support request] Hide cart in menu for a specific user role

Home Forums Support Hide cart in menu for a specific user role

Viewing 15 posts - 1 through 15 (of 33 total)
  • Author
    Posts
  • #2192487
    Deyson

    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! ๐Ÿ˜Š

    #2192509
    David
    Staff
    Customer Support

    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;
    }
    #2193694
    Deyson

    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! ๐Ÿ˜Š

    #2193709
    David
    Staff
    Customer Support

    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

    #2193725
    Deyson

    The cart submenu stopped working and I could not figure out why. ๐Ÿ™

    #2193763
    Ying
    Staff
    Customer Support

    Hi Deyson,

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

    Let me know!

    #2193786
    Deyson

    It is checked. ๐Ÿ˜Š

    Thank you and have an amazing day! ๐Ÿ˜Š

    #2194024
    Deyson

    I am sorry, I had meant it is Ticked. ๐Ÿ˜Š

    #2194225
    Ying
    Staff
    Customer Support

    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!

    #2194596
    Deyson

    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. ๐Ÿค”

    #2194604
    David
    Staff
    Customer Support

    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.

    #2194661
    Deyson

    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! ๐Ÿ˜Š

    #2194674
    David
    Staff
    Customer Support

    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.

    #2194678
    Deyson

    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! ๐Ÿ˜Š

    #2194681
    David
    Staff
    Customer Support

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

Viewing 15 posts - 1 through 15 (of 33 total)
  • You must be logged in to reply to this topic.