Hi there!
I understand that you want to hide the “Add to Cart” button without removing the product from Google. Since you mentioned that you hid the button using CSS but it caused the product to appear as out of stock, that is indeed unusual — simply hiding the button with CSS should not affect the stock status.
However, it’s possible that the stock quantity display is suppressed when the “Add to Cart” button is hidden.
That said, you can try using the following code to hide the “Add to Cart” button for specific products without affecting their visibility on Google:
add_filter('woocommerce_is_purchasable', 'custom_make_product_not_purchasable', 10, 2);
function custom_make_product_not_purchasable($purchasable, $product) {
$excluded_ids = array(5472, 5462); // Replace with your product IDs
if (in_array($product->get_id(), $excluded_ids)) {
return false;
}
return $purchasable;
}
Note: You’ll need to replace 5472 and 5462 with the product IDs for which you want to hide the “Add to Cart” button.
If that does not help, I can recommend WooExperts and Codeable.io as options for getting professional help. Alternatively, you can also ask your development questions in the WooCommerce Community Slack as custom code falls outside our usual scope of support
Hi there,
We haven’t heard back in a bit, so I’ll go ahead and mark this as resolved for now. If you’d like to pick things back up later, we’re just a message away!
Apart from this, if you have a moment, we’d really appreciate a review: https://ww.wp.xz.cn/support/plugin/woocommerce/reviews/#new-post