-1

How to hide the button "Add to cart" for the user, if it has a membership, I mean this is not an ordinary logged-in user, namely a member of a particular group, in this case just having a membership, without specifying a specific group... and display button if it does not has a membership. ?

Thought to do a simple check: If the person is logged in and if the value from the field in the database is equal to one, then execute the code at the link below, otherwise show the button. But how to write such a check in php? How to make the database was connected and checked what value?

function remove_loop_button(){
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
}
add_action('init','remove_loop_button');

Here's the code as if the delete button? http://pastebin.com/6mHybx2w

mujuonly
  • 11,370
  • 5
  • 45
  • 75
Danil
  • 11

1 Answers1

1

It is as simple as if else statement. Go to the place where cart is being rendered and enclose it inside a block similar to :-

<?php
if ( is_user_logged_in() && !is_member() ) {
    echo  '<div class="cart"><button class="btn btn-primary btn-sm">Shopping Cart</button> </div>';
}
?>

Now you have to figure out how you will get this !is_member(). If you have value 0, 1 in database for member and non member then you can easily compare that in if else statement.

Here you are simply comparing for membership and logged in and then populating cart based on both condition.

RanchiRhino
  • 786
  • 4
  • 21
  • Either you need to write a function to return if user is member or not or you can use many other ways to check for membership. – RanchiRhino Apr 18 '16 at 17:43