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

  • 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 3 replies - 1 through 3 (of 3 total)
  • 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 3 days, 5 hours ago by  logicrays.

    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

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

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