Hide “Add to cart” button when the product price is zero

前端 未结 2 1444
孤街浪徒
孤街浪徒 2021-01-17 02:15

I have an event based WordPress website on that I sell tickets using WooCommerce. Is there any way to hide the \"add to cart\" button for the product having cost zero?

相关标签:
2条回答
  • 2021-01-17 03:03

    You write this code in your theme function.php

    function remove_add_to_cart_on_0 ( $purchasable, $product ){
            if( $product->get_price() == 0 )
                $purchasable = false;
            return $purchasable;
        }
        add_filter( 'woocommerce_is_purchasable', 'remove_add_to_cart_on_0', 10, 2 );
    
    0 讨论(0)
  • 2021-01-17 03:22

    This code work like charm in function.php using this two filter.

    add_filter('remove_add_to_cart', 'my_woocommerce_is_purchasable', 10, 2);
    function remove_add_to_cart($is_purchasable, $product) {
            if( $product->get_price() == 0 )
                $is_purchasable = false;
                return $purchasable;   
    }
    
    
    function remove_add_to_cart_on_0 ( $purchasable, $product ){
            if( $product->get_price() == 0 )
                $purchasable = false;
            return $purchasable;
        }
    add_filter( 'woocommerce_is_purchasable', 'remove_add_to_cart_on_0', 10, 2 );
    
    0 讨论(0)
提交回复
热议问题