Skip to content

Instantly share code, notes, and snippets.

@mmilosheski
Created February 3, 2020 13:28
Show Gist options
  • Save mmilosheski/c6ddd09c78cbb2a31d23ce11e2d62d56 to your computer and use it in GitHub Desktop.
Save mmilosheski/c6ddd09c78cbb2a31d23ce11e2d62d56 to your computer and use it in GitHub Desktop.
<?php
/**
* @snippet Hide Price & Add to Cart for Logged Out Users
* @author Mile Milosheski
* @testedwith WooCommerce 3.3.4
*/
function hide_add_cart_not_logged_in() {
if ( !is_user_logged_in() ) {
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 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
}
}
add_action( 'init', 'hide_add_cart_not_logged_in' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment