Ocultar preus a usuaris registrats

/** Oculta precio y añadir al carrito a usuarios no conectados **/
add_filter('woocommerce_get_price_html', 'ayudawp_show_price_logged');
 
function ayudawp_show_price_logged($price){
if(is_user_logged_in() ){
return $price;
}
else
{
add_action( 'woocommerce_single_product_summary', 'ayudawp_print_login_to_see', 31 );
add_action( 'woocommerce_after_shop_loop_item', 'ayudawp_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 ayudawp_print_login_to_see() {
echo '<a href="' . get_permalink(wc_get_page_id('myaccount')) . '">' . __('Accede para ver los precios', 'theme_name') . '</a>';
}
  • Autor de l'entrada:
  • Categoria de l'entrada:Wordpress