• Hi Folks,

    I’ve used the following code to hide prices on our ‘Services’ WooCommerce category until the visitor logs in:

    // Specific product category archive and shop pages
    add_action( 'woocommerce_after_shop_loop_item_title', 'hide_loop_product_prices', 1 );
    function hide_loop_product_prices(){
        global $product;
        if (! is_user_logged_in()) {
    
            if(  is_product_category('services') || has_term( 'services', 'product_cat', $product->get_id() ) ){
                // Hide prices
                remove_action('woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
                // Hide add-to-cart button
                remove_action('woocommerce_after_shop_loop_item','woocommerce_template_loop_add_to_cart', 10 );
    
                add_action( 'woocommerce_single_product_summary', 'insight_print_register_to_see', 31 );
                add_action( 'woocommerce_after_shop_loop_item', 'insight_print_register_to_see', 99 );
           }
           else
           {
                add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
                add_action('woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
    
                remove_action('woocommerce_single_product_summary', 'insight_print_register_to_see', 31);
    remove_action('woocommerce_after_shop_loop_item','insight_print_register_to_see', 99 );
           }
        }
    }
    
    // Single product pages
    add_action( 'woocommerce_single_product_summary', 'hide_single_product_prices', 1 );
    function hide_single_product_prices(){
        global $product;
        if (! is_user_logged_in()) {
            if(is_product_category('services') || has_term( 'services', 'product_cat', $product->get_id() ) ):
    
                // Hide prices
                remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
                // Hide add-to-cart button, quantity buttons (and attributes dorpdowns for variable products)
                if( ! $product->is_type('variable') ){
                    remove_action('woocommerce_single_product_summary','woocommerce_template_single_add_to_cart', 30 );
                } else {
                    remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20 );
                }
                add_action( 'woocommerce_single_product_summary', 'insight_print_register_to_see', 31 );
    
            endif;
        }
    }
    
    function insight_print_register_to_see() {
        echo '<a href="' . get_permalink(wc_get_page_id('myaccount')) . '">' . __('Login/Register to see Price', 'theme_name') . '</a>';
    }

    This works on the WooCommerce category page, but not on the category’s /product/massage-deposit/ product pages, which are built using Elementor.

    How do I hide the price of a specific WooCommerce category’s product pages that use Elementor-built layouts?

    Thanks,
    Steve

    • This topic was modified 5 years, 4 months ago by insightdes.
    • This topic was modified 5 years, 4 months ago by Jan Dembowski.

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

Viewing 1 replies (of 1 total)
  • Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    Looking at your site, you are an Elementor Pro user. The author can’t have a conversation with customers here. That’s not permitted for anyone.

    For pro or commercial product support please contact the author directly on their site. This includes any pre-sales topics as well.

    As the author is aware, commercial products are not supported in these forums. I am sure they will have no problem supporting you there.

Viewing 1 replies (of 1 total)
  • The topic ‘hide price until login’ is closed to new replies.