{"id":12162154,"date":"2019-11-22T02:56:36","date_gmt":"2019-11-22T02:56:36","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/hide-price-until-login\/"},"modified":"2019-11-26T03:06:33","modified_gmt":"2019-11-26T03:06:33","slug":"hide-price-until-login","status":"closed","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/hide-price-until-login\/","title":{"rendered":"hide price until login"},"content":{"rendered":"<p>Hi Folks,<\/p>\n<p>I&#8217;ve used the following code to hide prices on our &#8216;Services&#8217; WooCommerce category until the visitor logs in:<\/p>\n<pre><code>\/\/ Specific product category archive and shop pages\nadd_action( &#039;woocommerce_after_shop_loop_item_title&#039;, &#039;hide_loop_product_prices&#039;, 1 );\nfunction hide_loop_product_prices(){\n    global $product;\n    if (! is_user_logged_in()) {\n\n        if(  is_product_category(&#039;services&#039;) || has_term( &#039;services&#039;, &#039;product_cat&#039;, $product-&gt;get_id() ) ){\n            \/\/ Hide prices\n            remove_action(&#039;woocommerce_after_shop_loop_item_title&#039;, &#039;woocommerce_template_loop_price&#039;, 10 );\n            \/\/ Hide add-to-cart button\n            remove_action(&#039;woocommerce_after_shop_loop_item&#039;,&#039;woocommerce_template_loop_add_to_cart&#039;, 10 );\n\n            add_action( &#039;woocommerce_single_product_summary&#039;, &#039;insight_print_register_to_see&#039;, 31 );\n            add_action( &#039;woocommerce_after_shop_loop_item&#039;, &#039;insight_print_register_to_see&#039;, 99 );\n       }\n       else\n       {\n            add_action( &#039;woocommerce_after_shop_loop_item&#039;, &#039;woocommerce_template_loop_add_to_cart&#039;, 10 );\n            add_action(&#039;woocommerce_after_shop_loop_item_title&#039;, &#039;woocommerce_template_loop_price&#039;, 10 );\n\n            remove_action(&#039;woocommerce_single_product_summary&#039;, &#039;insight_print_register_to_see&#039;, 31);\nremove_action(&#039;woocommerce_after_shop_loop_item&#039;,&#039;insight_print_register_to_see&#039;, 99 );\n       }\n    }\n}\n\n\/\/ Single product pages\nadd_action( &#039;woocommerce_single_product_summary&#039;, &#039;hide_single_product_prices&#039;, 1 );\nfunction hide_single_product_prices(){\n    global $product;\n    if (! is_user_logged_in()) {\n        if(is_product_category(&#039;services&#039;) || has_term( &#039;services&#039;, &#039;product_cat&#039;, $product-&gt;get_id() ) ):\n\n            \/\/ Hide prices\n            remove_action(&#039;woocommerce_single_product_summary&#039;, &#039;woocommerce_template_single_price&#039;, 10 );\n            \/\/ Hide add-to-cart button, quantity buttons (and attributes dorpdowns for variable products)\n            if( ! $product-&gt;is_type(&#039;variable&#039;) ){\n                remove_action(&#039;woocommerce_single_product_summary&#039;,&#039;woocommerce_template_single_add_to_cart&#039;, 30 );\n            } else {\n                remove_action( &#039;woocommerce_single_variation&#039;, &#039;woocommerce_single_variation_add_to_cart_button&#039;, 20 );\n            }\n            add_action( &#039;woocommerce_single_product_summary&#039;, &#039;insight_print_register_to_see&#039;, 31 );\n\n        endif;\n    }\n}\n\nfunction insight_print_register_to_see() {\n    echo &#039;&lt;a href=&quot;&#039; . get_permalink(wc_get_page_id(&#039;myaccount&#039;)) . &#039;&quot;&gt;&#039; . __(&#039;Login\/Register to see Price&#039;, &#039;theme_name&#039;) . &#039;&lt;\/a&gt;&#039;;\n}<\/code><\/pre>\n<p>This works on the WooCommerce category page, but not on the category&#8217;s \/product\/massage-deposit\/ product pages, which are built using Elementor.<\/p>\n<p>How do I hide the price of a specific WooCommerce category&#8217;s product pages that use Elementor-built layouts?<\/p>\n<p>Thanks,<br \/>\nSteve<\/p>\n","protected":false},"template":"","class_list":["post-12162154","topic","type-topic","status-closed","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/12162154","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":2,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/12162154\/revisions"}],"predecessor-version":[{"id":12175004,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/12162154\/revisions\/12175004"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=12162154"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}