Created
February 17, 2019 00:58
-
-
Save ofernandolopes/212f37d7e0b84981862b835c48cf63cc to your computer and use it in GitHub Desktop.
Show values and add to cart only for users who have logged in to WooCommerce.
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
| // | |
| //Show values and add to cart only for users who have logged in to WooCommerce. | |
| // | |
| add_action( 'init', 'wc_hide_price_add_cart_not_logged_in' ); | |
| function wc_hide_price_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( 'woocommerce_single_product_summary', 'wc_print_login_to_see', 31 ); | |
| add_action( 'woocommerce_after_shop_loop_item', 'wc_print_login_to_see', 11 ); | |
| } | |
| } | |
| function wc_print_login_to_see() { | |
| echo 'Faça <a href="' . get_permalink(wc_get_page_id('myaccount')) . '">' . __('login') . '</a> para ver os preços'; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment