I want to disable button "Add to cart" when product is available on backorder.
I tried something like this, but doesn't work at all:
function remove_add_to_cart ($product){
if($product->is_on_backorder){
add_filter( 'woocommerce_is_purchasable', '__return_false');}}
any suggestion please?
CodePudding user response:
One solution (depending on what you actually want to do) could be to remove the add_to_cart form entirely if the product is on backorder. There could be other solutions as well, but your question is a little vague. This is specifically for the product single page. You didn't specify in the question.
add_action('woocommerce_single_product_summary', 'check_if_backordered', 1 );
function check_if_backordered(){
global $product;
if ($product->is_on_backorder()){
remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30);
// Here you can insert whatever you want in its place
}
}