• Resolved infofinal

    (@infofinal)


    Hello, When the product is out of stock, its change the button from add to cart to read more, and i didn’t need it. how can delete this button and only show the add to cart but not clickable

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

Viewing 3 replies - 1 through 3 (of 3 total)
  • Ahir Hemant

    (@hemant-ahir)

    Hi
    try to add this code in functions.php

    // Remove "Read More" button and disable "Add to Cart" button when the product is out of stock
    add_action('wp', 'customize_product_buttons');
    function customize_product_buttons() {
        global $product;
    
        // Check if it's a single product page
        if (is_product()) {
            // Check if the product is out of stock
            if (!$product->is_in_stock()) {
                // Remove "Read More" button
                remove_action('woocommerce_after_single_product', 'woocommerce_template_single_excerpt', 20);
    
                // Disable "Add to Cart" button
                remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30);
                add_action('woocommerce_single_product_summary', 'display_disabled_add_to_cart_button', 30);
            }
        }
    }
    
    // Display disabled "Add to Cart" button
    function display_disabled_add_to_cart_button() {
        global $product;
        
        // Output the button with the 'disabled' attribute
        echo '<button type="submit" class="single_add_to_cart_button button alt" disabled>Add to Cart</button>';
    }
    
    Thread Starter infofinal

    (@infofinal)

    Thank you for your reply,

    I have tried the code, the button still “read more” but when click on it return to an error page.

    Hi @infofinal

    Thanks for reaching out!

    When the product is out of stock, its change the button from add to cart to read more, and i didn’t need it. how can delete this button and only show the add to cart but not clickable

    I did some research and found these articles could be a good starting point:

    Hope this helps!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Out Of Stock’ is closed to new replies.