Skip to content

Instantly share code, notes, and snippets.

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 Oscar-Abad-Folgueira/32cc02217ff4071af4d5a726251d2e10 to your computer and use it in GitHub Desktop.
Save Oscar-Abad-Folgueira/32cc02217ff4071af4d5a726251d2e10 to your computer and use it in GitHub Desktop.
WooCoomerce Snippet - Ocultar precios a usuarios no registrados
<?php
/**
* @snippet WooCoomerce Snippet - Ocultar precios a usuarios no registrados
* @author Oscar Abad Folgueira
* @author_url https://www.oscarabadfolgueira.com
* @snippet_url https://www.oscarabadfolgueira.com/ocultar-precios-a-usuarios-no-registrados-en-woocommerce
*/
add_filter( 'woocommerce_variable_sale_price_html', 'update_price_html', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'update_price_html', 10, 2 );
add_filter( 'woocommerce_get_price_html','update_price_html', 999, 2 );
function update_price_html( $html, $product ) {
if(!is_user_logged_in()) { // Si el usuario no está logueado
add_filter( 'woocommerce_is_purchasable', '__return_false');
$html = "Necesitas estar registrado para ver los precios";
return $html;
} else {
return $html;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment