Skip to content

Instantly share code, notes, and snippets.

@Acephalia
Created April 21, 2024 10:15
Show Gist options
  • Save Acephalia/94ac3f2c690286a28ff9413ba8e9f0d6 to your computer and use it in GitHub Desktop.
Save Acephalia/94ac3f2c690286a28ff9413ba8e9f0d6 to your computer and use it in GitHub Desktop.
Woocommerce hide add to cart button for non logged in users but show stock.
//Hide add to cart button for non logged in users but show stock.
function hide_add_to_cart_for_non_logged_in_users() {
if (!is_user_logged_in()) {
?>
<style>
form.cart {
display: none;
}
</style>
<div class="login-to-purchase">
<p>Please <a href="<?php echo get_permalink(get_option('woocommerce_myaccount_page_id'));?>">log in or register</a> to purchase this product.</p>
</div>
<?php
}
}
add_action('woocommerce_single_product_summary', 'hide_add_to_cart_for_non_logged_in_users');
@Acephalia
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment