Adrian Axinte Adrian Axinte - 3 years ago 109
PHP Question

Hide price in Woocommece if user not activated

I'm using WooCommerce for my new WordPress store and I want to hide prices from "pending" users, untill I will approve them.

I use New User Approve plugin to add "pending" status for all new users but I don't know how to hide the price. I did somthing but it's not working:

if (is_user_logged_in()) {
$nua = pw_new_user_approve();
$status = $nua->get_user_status(get_current_user_id());
if ($status !== 'pending') {
// User is logged in and approved.
if ($price_html = $product->get_price_html()) : ?>
<span class="price"><?php echo $price_html; ?></span>
<?php endif;

Can you help me please?

Answer Source

I have the exact same issue and just found this by chance.

Your code looks alright, I chucked it in blindly and fixed up the PHP errors via a PHP SYntax Checker (googled it).

Here is the working code, it just needed to be closed off on the < ? php ? > tags properly, and also your curly braces { } and IF/END IF's slightly.

< ? php if (is_user_logged_in()) {

$nua = pw_new_user_approve();
$status = $nua->get_user_status(get_current_user_id());

if ($status !== 'pending') { ?>
      <?php if ($price_html = $product->get_price_html()) : ?>
        <span class="price"><?php echo $price_html; ?></span>
      <?php endif; ?>

< ? php }; }; ? >

** There is no space between the the < and ? and php, i had to write it in like that here for full code visible

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download