• I already hidden the zero price for the front-end but in the side cart I can not hide “Price: 0,00€” and If I use CSS to hide class id “xoo-wsc-price” it also hides the non-zero price.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author xootix

    (@xootix)

    I could not find any product on your site with 0 price.
    Its not easy, try adding this code to your functions.php

    add_filter( 'woocommerce_cart_item_price', function( $price_html, $cart_item, $cart_item_key ){
    	if( $cart_item['data']->get_price() === 0 ){
    		return '<div class="xoo-wsc-hide-price">'.$price_html.'</div>';
    	}
    	return $price_html;
    }, 9999, 3 );
    
    add_action( 'wp_footer', function(){
    	
    	?>
    
    	<style type="text/css">
    		.xoo-wsc-hide-price-cont .xoo-wsc-price, .xoo-wsc-hide-price-cont .xoo-wsc-ptotal {
    		    display: none;
    		}
    	</style>
    
    	<script type="text/javascript">
    		jQuery(document).ready(function($){
    			function hide_zero_price(){
    				$('.xoo-wsc-hide-price').each(function(index, el){
    					$(el).parents('.xoo-wsc-sum-col').addClass('xoo-wsc-hide-price-cont');
    				})
    			}
    			$(document.body).on('wc_fragments_refreshed', function(){
    				setTimeout(hide_zero_price(), 50);
    			});
    		})
    			
    		
    	</script>
    	<?php
    } );
    • This reply was modified 4 years, 10 months ago by xootix. Reason: code update
    Thread Starter mendoadmin

    (@mendoadmin)

    Hi @xootix

    Yes, you will not find the zero price directly in our live site product-page because the zero-priced product is an appointment.

    What you can do is, add to cart (save and proceed) any product (e.g this in this URL) then an appointment will pop-out when the page loads in the cart page.

    I tried your code above but it did not change anything in the front-end.
    Here is a screenshot for your reference with zero-priced product

    Thread Starter mendoadmin

    (@mendoadmin)

    @xootix

    Good day!
    I manage to make it work by modifying the conditions based on a specific product ID’s.

    Can you check the modified code below if it’s already enough or can we still improve it?

    add_filter( 'woocommerce_cart_item_price', function( $price_html, $cart_item, $cart_item_key ){
    	if( $cart_item['product_id'] === 2286 || 5238 || 5458 ){
    		return '<div class="xoo-wsc-hide-price">'.$price_html.'</div>';
    	}
    	return $price_html;
    }, 9999, 3 );
    
    add_action( 'wp_footer', function(){
    	
    	?>
    
    	<style type="text/css">
    		.xoo-wsc-hide-price-cont .xoo-wsc-price, .xoo-wsc-hide-price-cont .xoo-wsc-ptotal, .xoo-wsc-hide-price-cont .xoo-wsc-qtybox {
    		    display: none;
    		}
    	</style>
    
    	<script type="text/javascript">
    		jQuery(document).ready(function($){
    			function hide_zero_price(){
    				$('.xoo-wsc-hide-price').each(function(index, el){
    					$(el).parents('.xoo-wsc-sum-col').addClass('xoo-wsc-hide-price-cont');
    				})
    			}
    			$(document.body).on('wc_fragments_refreshed', function(){
    				setTimeout(hide_zero_price(), 50);
    			});
    		})
    			
    		
    	</script>
    	<?php
    } );
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Hide ZERO price in the side cart’ is closed to new replies.