S
S
Sanyok2019-07-16 22:12:03
WooCommerce
Sanyok, 2019-07-16 22:12:03

How to remove the "Add to Cart" button for products without sizes and weights in Woocommerce?

Good afternoon! Can you please tell me how to remove the Add to Cart button for products with sizes zero?
I have a working code that removes a button if the weight is zero. What if there are no sizes?

add_filter('remove_add_to_cart', 'my_woocommerce_is_purchasable', 10, 2);
function remove_add_to_cart($is_purchasable, $product) {
        if( $product->get_weight() == 0 )
            $is_purchasable = false;
            return $purchasable;   
}


function remove_add_to_cart_on_0 ( $purchasable, $product ){
        if( $product->get_weight() == 0 )
            $purchasable = false;
        return $purchasable;
    }
add_filter( 'woocommerce_is_purchasable', 'remove_add_to_cart_on_0', 10, 2 );

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pychev Anatoly, 2019-07-17
@pton

Sizes are the same product properties as "weight" Just check them against the corresponding values ​​in the same function.
Here is a link to the Woo documentation
And a screenshot of it
By the way, in the first block of code that you provided, the hook and the name of the function are mixed up in places.
Most likely you wanted to write it like this

add_filter('woocommerce_is_purchasable','remove_add_to_cart', 10, 2);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question