• Resolved petervdaal

    (@petervdaal)


    Hi,
    I have set up my wordpress website in a way that people who are logged in can see prices and people who are not logged in can’t. I did this with the code below, but unfortunately it doesn’t work with the TG: product carousel on the front page. It also doesn’t work with the TG: product grid on the front page. This also applies to the product list that appears on the right of the product page.

    Can someone help me adjust the code so that no price is visible on the homepage and the product page (product list) until someone logs in?

    Thank you in advance. Below is the code I used.

    ——————————————————————–

    /**
     * @snippet       Hide Price & Add to Cart for Logged Out Users
     * @how-to        Get CustomizeWoo.com FREE
     * @author        Rodolfo Melogli, BusinessBloomer.com
     * @testedwith    WooCommerce 4.6
     * @donate $9     https://businessbloomer.com/bloomer-armada/
     */
      
    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>';
    }
    • This topic was modified 3 years, 5 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Developing with WordPress topic

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

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Hide prices TG: product-carousel’ is closed to new replies.