• Resolved optimweb

    (@optimweb)


    I added this snipped in the functions.php

    add_filter('wwp_hide_price_and_add_to_cart_button', 'hide_price_and_cart', 10, 1);
    function hide_price_and_cart($non_wholesale_user)
    {
        global $current_user, $wc_wholesale_prices;
    
        $user_wholesale_role = $wc_wholesale_prices->wwp_wholesale_roles->getUserWholesaleRole();
    
        if (isset($current_user)) {
    
            if (empty($user_wholesale_role)) {
                $non_wholesale_user = true;
                add_filter('wwp_display_replacement_message', function ($message) {
                    $message = '<a href="' . get_permalink(wc_get_page_id('myaccount')) . '">' . __('Register as wholesale customer to see prices', 'woocommerce-wholesale-prices') . '</a>';
    
                    return $message;
                });
            }
        }
    
        return $non_wholesale_user;
    }

    I want to make it apply only on certain categories and not on all products.

    Can you help me?

Viewing 1 replies (of 1 total)
  • Plugin Support Fauzan Azizie

    (@fauzanade)

    Hi @optimweb,

    You can use this snippet to hide price for non-wholesale in specific category:

    add_filter('wwp_hide_price_and_add_to_cart_button', function($non_wholesale_user){
    
        global $current_user;
    
        if(!is_user_logged_in() && get_option( 'wwp_hide_price_add_to_cart' ) === 'yes' ) {
    
            $non_wholesale_user = false;
        }
    
        return $non_wholesale_user;
    
    }, 10, 1);
    
    add_filter( 'woocommerce_get_price_html', function( $price, $product ) {
    
        // replace this with the category you like to filter e.g. array('music', 'accessories', ...etc)
        $terms = array('hoodies');
    
        if (!is_user_logged_in() && get_option('wwp_hide_price_add_to_cart') === 'yes' && is_object_in_term( get_the_ID(), 'product_cat', $terms)){
    
            $price = '<a href="' . get_permalink(wc_get_page_id('myaccount')) . '">' . __('Register as wholesale customer to see prices', 'woocommerce-wholesale-prices') . '</a>';
    
            remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart');
    		remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30);
    
        }
    
        return $price;
    
    }, 10, 2);

    Please kindly update this line:

    $terms = array(‘hoodies’);

    With your categories slugs.

Viewing 1 replies (of 1 total)
  • The topic ‘Hide Price for Non-Wholesale only in a specific category’ is closed to new replies.