Problem disabling the Add to Cart button for unregistered users
-
Greetings.
I use the following code in the functions.php file in the child theme.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', 9999, 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 = "Necesita registrarse para ver precios"; return $html; } else { return $html; } }
This code works perfectly fine to hide prices from unregistered users. But in the case of hiding the “Add to cart” button, it presents the problem that it does not hide it in the first product in the category list, although it does for all other products.
This problem occurs for any product category and / or subcategory, change the “Add to cart” button for the “Read more” button in all the products in the list except the first one.Versions:
Wordpress 5.8.1
Wocommerce: 5.7.1
Theme: Ocolus (child)The page I need help with: [log in to see the link]
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Problem disabling the Add to Cart button for unregistered users’ is closed to new replies.