Hide product prices for non-logged in users

41 seconds

When users view your products, they’ll see a screen similar to the one below of an example Topicals product.

The details shown are the vendor name, product title and price along with the add to cart button and categories.

WP Dispensary eCommerce Lavender Whipped Body Budder

In eCommerce v1.3 we’ve introduced a new option that lets you hide the add to cart functionality from non-logged in users.

This article is going to show you how to take that one step further and hide the actual product prices from single items for non-logged in users.

It’s simple: place the code snippet below into your theme’s functions.php file.

<?php
/**
 * Hide single item price display for non-logged in users
 *
 * @param     string $display_price
 */
function acme_single_item_price_display( $display_price ) {
    // Get WPD settings from General tab.
    $wpdas_general = get_option( 'wpdas_general' );

    // Check if user is required to be logged in to shop.
    if ( isset( $wpdas_general['wpd_ecommerce_cart_require_login_to_shop'] ) ) {
        $login_to_shop = $wpdas_general['wpd_ecommerce_cart_require_login_to_shop'];
    } else {
        $login_to_shop = NULL;
    }

    // Hide price if user is required to be logged in to shop.
    if ( ! is_user_logged_in() && 'on' == $login_to_shop ) {
        $display_price = '';
    } else {
        $display_price = $display_price;
    }

    return $display_price;
}
add_filter( 'wpd_ecommerce_single_item_price', 'acme_single_item_price_display' );

The result will be product details displayed without the product price for non-logged in users, like the image below.

WP Dispensary eCommerce require login to shop display
single product view

Was this article helpful?