0
votes

In WooCommerce I am trying to remove add to cart from product keeping the stock information.

I tried to do it with a plugin but it also remove the stock information.

Is there any way to remove Add to Cart button keeping stock information in single product pages ?

1

1 Answers

0
votes

The following code will remove add to cart form from single product on simple product type but will display the stock information:

// Single products (Simple): remove add to cart button and keep stock info
add_action( 'woocommerce_single_product_summary', 'remove_simple_product_add_to_cart_button', 1 );
function remove_simple_product_add_to_cart_button() {
    global $product;

    // For simple products type
    if( $product->is_type( 'simple' ) && $product->is_purchasable() ) {
        remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );
        add_action( 'woocommerce_single_product_summary', 'show_stock_info', 30 );
    }
}

// Function that stock info
function show_stock_info() {
    global $product;

    echo wc_get_stock_html( $product );
}

Code goes in function.php file of your active child theme (active theme). tested and works.

enter image description here