After hours of research, i found a somewhat weird solution but somehow works. I used the woocommerce_is_purchasble hook. It passes 2 parameters is_purchasable
and object
(WC_Product
) Which I can now get the product total number of stock.
Here’s what I did.
function order_is_purchasable($is_purchasable, $object) {
if($object->get_total_stock() > 50){
echo '<a style="margin-bottom: 10px;" href="" class="button">Call to purchase</a>';
return false;
}else{
return true;
}
}
add_filter('woocommerce_is_purchasable', 'order_is_purchasable', 10, 2);
The echo displays the button linking to my desired page for special payment.