Support » Plugin: WooCommerce » Add to cart button and price when logged in

  • Resolved iansingleton67

    (@iansingleton67)



    We have had add to cart buttons and and pricing showing to logged in users for some time. For some reason the first product on the shop page doesn’t show the button and the price is not aligned with all the other prices. This happens on all our shop pages so it isn’t specific to one product. Has this happened to any other user? I can provide a screenshot of the issue.

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • logicrays

    (@logicrays)

    Please add function.php

    add_action( 'init', 'bbloomer_hide_price_add_cart_not_logged_in' );
     
    function bbloomer_hide_price_add_cart_not_logged_in() { 
    if ( !is_user_logged_in() ) {       
     remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
     remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
     remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
     remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );  
     add_action( 'woocommerce_single_product_summary', 'bbloomer_print_login_to_see', 31 );
     add_action( 'woocommerce_after_shop_loop_item', 'bbloomer_print_login_to_see', 11 );
    }
    }
     
    function bbloomer_print_login_to_see() {
    echo '<a href="' . get_permalink(wc_get_page_id('myaccount')) . '">' . __('Login to see prices', 'theme_name') . '</a>';
    }

    Thanks

    • This reply was modified 6 months ago by  logicrays.
    iansingleton67

    (@iansingleton67)

    This is the code that we are using

    `// Add buttons and price on shop for logged in users only

    add_action( ‘woocommerce_after_shop_loop_item’, ‘add_loop_button’, 30 );

    function add_loop_button() {
    if(is_user_logged_in()){
    if( is_product_category() || is_shop()) {
    add_action( ‘woocommerce_after_shop_loop_item’, ‘woocommerce_template_loop_add_to_cart’ );
    add_action( ‘woocommerce_after_shop_loop_item_title’, ‘woocommerce_template_loop_price’, 10 );
    }
    }
    }

    add_action( ‘template_redirect’, ‘addcss’ );

    function addcss() {
    if(is_user_logged_in()){
    if (is_product_category() || is_shop()) {
    echo ‘<style type=”text/css”>
    span.price{position:absolute;bottom:90px!important;}
    span.amount{border-bottom:0!important;}
    </style>’;
    }
    if(is_single()){
    echo ‘<style type=”text/css”>span.price{display:none;}

    .product-image-tools a {
    padding-top:10px;

    }

    Displays buttons and prices for all but the first product. We are using the flatsome theme

    iansingleton67

    (@iansingleton67)

    Forgot to mention we are running the latest version of Word Press.

    Plugin Support dougaitken

    (@dougaitken)

    Automattic Happiness Engineer

    Hi @iansingleton67

    Looking at the site today, I don’t see any add_to_cart buttons on the category archive pages.

    Did you find a solution for this or have you chosen to move away from that behavior?

    Thanks,

    Plugin Support Hannah S.

    (@fernashes)

    Automattic Happiness Engineer

    We haven’t heard back from you in a while, so I’m going to mark this as resolved – if you have any further questions, you can start a new thread.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.