Skip to content

Instantly share code, notes, and snippets.

@mattiasghodsian
Last active April 28, 2023 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattiasghodsian/0edee15165a0ed1d0e5ae0307db5168d to your computer and use it in GitHub Desktop.
Save mattiasghodsian/0edee15165a0ed1d0e5ae0307db5168d to your computer and use it in GitHub Desktop.
Woocommerce Show price only for logged-in users
/**
* 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