Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mmilosheski/c3bd57c745d86be165619d7c51bd0c0a to your computer and use it in GitHub Desktop.
Save mmilosheski/c3bd57c745d86be165619d7c51bd0c0a to your computer and use it in GitHub Desktop.
Removes the prices on products when customer is not logged in.. Shows prices when the customer is logged in
<?php
// Hide prices
add_filter('woocommerce_get_price_html', 'show_price_logged');
function show_price_logged($price){
if(is_user_logged_in() ) {
return $price;
} else {
add_action( 'woocommerce_single_product_summary', 'print_login_to_see', 31 );
add_action( 'woocommerce_after_shop_loop_item', 'print_login_to_see', 11 );
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
}
}
function print_login_to_see() {
echo '<a href="' . get_permalink(woocommerce_get_page_id('myaccount')) . '" class="contact-form-submit-input">' . __('Login to see prices', '') . '</a>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment