• Found a good piece of code that will work for me but I need to modify it slightly to get it to do what I want. here’s the code

    add_filter('woocommerce_get_price_html','members_only_price');
    function members_only_price($price){
    if(is_user_logged_in() ){
        return $price;
    }
    else return '<a href="' .get_permalink(woocommerce_get_page_id('myaccount')). '">Accede</a> o <a href="'.site_url('/wp-login.php?action=register&redirect_to=' . get_permalink()).'">Regístrate</a> para ver precios!'.remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' ).remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 ).remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 ).remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
    }

    I want to modify it so that it only hides the prices and card and does not have the hyperlink to login or register. Below is what I think will work. Will it?

    add_filter('woocommerce_get_price_html','members_only_price');
    function members_only_price($price){
    if(is_user_logged_in() ){
        return $price;
    }
    else return .remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart' ).remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 ).remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 ).remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
    }

  • The topic ‘Woocommerce Hide Prices If Not Logged In’ is closed to new replies.