• Hi,
    I need to hide my add to cart button on the condition where the price = 0.00. If the price is greater than 0.00 i would like the button to reappear.

    However i also use the WooTheme Wish List extension and i need the add to wish list button to remain. I would also like to change the text from Free to “Subscription Product” when the value is 0.00.

    This is only needed on the single product page as we do not show the add to cart anywhere else.

    Currently if the price is set to 0.00 i get the text at the top of the single product page saying “free” and the add to cart button remains as does the add to wish list button. If i remove the price all together the buttons also disappear hence why i need to “hide” the button to retain the wish list one.

    This seems possible as I have read lots on the forum but unfortunately i am not a programmer so i don’t really understand what to do or where to add the code.

    Could someone help me out and let me know what code to add and also where to add it.

    Many Thanks…

    Just for info, the reason i need to do this is because we run a subscription service, so products that are included in a subscription service do not need a price but do need to be shown so they can be added to a wish list. However sometimes we sell the products off so when they have a value i need the button to reappear so they can be added to the cart.
    Simply having zero doesn’t work because believe it or not people think they are free and try to add them to the cart to purchase !

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Pigsfoot

    (@pigsfoot)

    HI,
    I found this and managed to work out that it goes in the function.php file of my theme

    <?php
     /*
    	* Swop the 'Free!' price notice and hide the cart with 'POA' in WooCommerce
     */
        add_filter( 'woocommerce_variable_free_price_html',  'hide_free_price_notice' );
        add_filter( 'woocommerce_free_price_html',           'hide_free_price_notice' );
        add_filter( 'woocommerce_variation_free_price_html', 'hide_free_price_notice' );
    
    function hide_free_price_notice( $price ) {
        remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
        remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
        return 'POA';
    }
    ?>

    However, although it did work in that it changed the “Free” text to “POA” and also hid the “Add to Cart button” the “Add to Wishlist” button also disappeared.

    If i changed the value to 0.01 everything appeared again so it nearly there… i just need the Wish List button to stay.

    Can anyone help at all… Thanks

    Thread Starter Pigsfoot

    (@pigsfoot)

    Wow.. this thread is so busy… just wanted to Bump this to see if anyone can help. Thanks..

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Hide "Add to Cart" with If Condition’ is closed to new replies.