Created
April 21, 2024 10:15
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For reddit request : https://www.reddit.com/r/woocommerce/comments/1c7vxrk/lock_add_to_basket_button_until_logged_in_but/