• Resolved dave8441

    (@dave8441)


    A few products on my website are for display purposes only, and customers are advised to contact us for pricing. Since I did not enter the cost in the price field, no buy button is displayed which is what I want to happen. This method worked fine in the past. But now, Google is forcing me to enter a price due to their schema requirements. Here is the warning message I got in Google Search Console:

    Top critical issues*
    Either “price” or “priceSpecification” should be specified (in “offers”)
    *Critical issues prevent your page or feature from appearing in Search results.

    Obviously I can no longer leave the price field blank, otherwise Google will remove those pages from their search results. Is there an easy way to stop the buy button from appearing after I enter a price?

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

Viewing 4 replies - 1 through 4 (of 4 total)
  • you can hide the buy button with css

    Hi

    add_filter('woocommerce_is_purchasable', 'ahirwp_disable_buy_button', 10, 2);
    function ahirwp_disable_buy_button($purchasable, $product) {
        $disabled_product_ids = array(1, 2, 3); // Replace with the specific product IDs where you want to disable the buy button
    
        if (in_array($product->get_id(), $disabled_product_ids)) {
            return false; // Disable the buy button
        }
    
        return $purchasable;
    }
    

    In the above code, you need to modify the $disabled_product_ids array to include the specific product IDs for which you want to disable the buy button. Add the relevant product IDs inside the array.

    Once you’ve made the necessary changes, save the functions.php file.

    Now, when you visit the product pages with the specified product IDs, the buy button should be disabled.

    Remember to test the changes by visiting the relevant product pages to ensure that the buy button is disabled as expected.

    Thanks
    Ahir Hemant

    Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @dave8441

    I understand your concern about the issue you’re experiencing with Google’s schema requirements and the ‘Buy’ button display on your WooCommerce store.

    Google’s schema requirements indeed mandate that either the “price” or “priceSpecification” be specified in the “offers” section. This is to provide users with complete information about the product, which in turn aids in better search results and user experience. However, I understand that you want to hide the ‘Buy’ button for specific products on your website.

    Here’s some great news for you! You can easily accomplish this task in WooCommerce. Install a custom functions plugin such as “Code Snippets” and use the code snippet shared by @hemant-ahir above. This code snippet will allow you to hide the ‘Add to Cart’ button on any selected product.

    I hope this helps! If you have any further questions or need more assistance, feel free to ask.

    Thread Starter dave8441

    (@dave8441)

    Hi @hemant-ahir,

    Thank you for the code. But after rethinking this, it would be more practical to simply add those pages as exceptions in my Schema & Structured Data for WP & AMP plugin settings. Their plugin does not currently have an option to exclude individual pages, so I just requested it on their support site.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to disable buy button on specific product pages?’ is closed to new replies.