Every night I load in a CSV with my suppliers products. They remove and add products in every CSV. If a product is not in the CSV anymore and it was in the CSV before, my plugin will put the product visibility on hidden. This way the link still works, so no 404 errors in search console etc, but the product is not showing in my shop.
However, some customers still land on these links from different domains, i.e. google. They land on the "invisible product" and they have the possibility to click on the "in cart" button while the product is not available anymore.
Therefor my question: How can I (in functions.php?) make sure that when a product's visibility is hidden, the cart button is removed (a simple display: none; will do).
I use WP Import for importing the CSV and the way products are put on visibility:hidden is like this:
function my_is_post_to_delete($is_post_to_delete, $post_id, $import) {
// Get an instance of the product variation from a defined ID
$my_product = wc_get_product($post_id);
// Change the product visibility
$my_product->set_catalog_visibility('hidden');
// Save and sync the product visibility
$my_product->save();
return false;
}
So I need something like this:
If product_visibility
is 'hidden
' then remove add to cart button.