Created
January 11, 2017 09:41
-
-
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
This file contains hidden or 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
<?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