Last active
April 28, 2023 08:38
-
-
Save mattiasghodsian/0edee15165a0ed1d0e5ae0307db5168d to your computer and use it in GitHub Desktop.
Woocommerce Show price only for logged-in users
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
/** | |
* Title: Woocommerce Show price only for logged-in users | |
* Author: Mattias Ghodsian | |
* Description: Woocommerce Show price only for logged-in users | |
* Donate a cup of coffee: https://www.buymeacoffee.com/mattiasghodsian | |
* Donate Eth: 0xBBB96204E45D11C9799c6B12E6eE6F0d4A071Ef5 | |
* | |
* @param integer $price | |
* @param array $product | |
* return integer | |
**/ | |
add_filter( 'woocommerce_variable_sale_price_html', 'wc_hide_price', 10, 2 ); | |
add_filter( 'woocommerce_variable_price_html', 'wc_hide_price', 10, 2 ); | |
add_filter( 'woocommerce_get_price_html', 'wc_hide_price', 10, 2 ); | |
function wc_hide_price( $price, $product ) | |
{ | |
if ( is_user_logged_in() ) { | |
return $price; | |
}else{ | |
return '<a href="' . get_permalink( wc_get_page_id( 'myaccount' ) ) . '" class="button btn-loginprice">' . __('Login to see prices','theme_name') . '</a>'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment