I'm making a custom plugin for a WordPress powered page to disable a certain button on condition.
Context: To disable place order button if the user breached a certain credit limit.
I'm expecting that upon entering checkout page, the plugin will fire and check if the user exceeded the credit limit. If yes, it will then alert the user and disable the place order button.(OR create an overlay OR any other methods)
For now I have this:
function credit_limit_check()
{
/** page 13 is the check out page ID*/
if (is_page(13)) {
if (is_user_logged_in()) {
/* For reference purpose*/
/* get_user_meta( int $user_id, string $key = '', bool $single = false ) */
$ID = get_current_user_id();
$credit_val = get_user_meta($ID, 'credit_limit', true);
$outstanding_val = get_user_meta($ID, 'outstanding_credit', true);
$credit_breach = $credit_val - $outstanding_val;
if ($credit_breach <= 0) {
/*disable checkout button if not enough credit limit*/
echo '<button type="submit" class="button alt" name="woocommerce_checkout_place_order" id="place_order" value="Place order" data-value="Place order" disabled>Place order</button>';
echo '<script>alert("You have exceeded your credit limit, please make sure you have no outstanding bill")</script>';
} else {
print_r("Huzzah! Good news! You have enough credit to proceed!");
}
} else {
print_r("Please login with your account before proceeding.");
}
}
}
The only problem is that the functions actually creates an extra button on top of the page instead of disabling the original button. So I am wondering if this is actually doable, or do I have to modify the html files directly to achieve what is intended.(Preferably not)
Now, I do see some similar questions, but all of them require directly applying php in the html tags. It is not applicable for my situation as I am creating a wordpress custom plugin. (Which is an individual php file).


