如何在if条件下禁用按钮

  • 本文关键字:按钮 条件下 if php html
  • 更新时间 :
  • 英文 :


当未达到$needs_minimum_amount时,我正在尝试禁用一个按钮。我曾尝试过使用:document.getElementById("checkout button button alt-wc-forward"(.disabled=true;。但没有完全发挥作用。有人能帮忙吗?

function wc_minimum_order_amount() {
##  SETTINGS  ##
$minimum_amount = 13; // Define a minimum order amount
$category_ids   = array( 25, 28, 29 ); // Define your category ids in the array (or an empty array to disable)
$product_ids    = array(); // Define your product ids in the array (or an empty array to disable)

// Only on cart or checkout pages
if( WC()->cart->is_empty() || ! ( is_cart() || is_checkout() ) ) 
return; // Exit
$total_amount = WC()->cart->subtotal; // Items subtotal including taxes
if ( $total_amount < $minimum_amount ) {
$needs_minimum_amount = false; // Initializing
// Loop through cart items
foreach ( WC()->cart->get_cart() as $cart_item ) {
$product_id   = $cart_item['product_id'];
$variation_id = $cart_item['variation_id'];

// 1. Check for matching product categories
if( sizeof($category_ids) > 0 ) {
$taxonomy = 'product_cat';
if ( has_term( $category_ids, $taxonomy, $product_id ) ) { 
$needs_minimum_amount = true;
break;
}
}
// 2. Check for matching product Ids
if( sizeof($product_ids) > 0 ) {
if ( array_intersect( $product_ids, array($product_id, $variation_id) ) ) { 
$needs_minimum_amount = true;
break; // Stop the loop
}
}
}
if( $needs_minimum_amount ) {
wc_print_notice( sprintf( 
__("Minimale bestelling voor sweets is 12,50 voor een bestelling."), 
wc_price( $minimum_amount ), 
wc_price( $total_amount )
), 'error' );

}
}

}

这是我试图禁用的按钮:

<a href="https://smileyscandyshop.nl/afrekenen/" class="checkout-button button alt wc-forward">
Doorgaan naar afrekenen</a>
<input type="button" value="Add to Cart" <?php if ($prod_qty == '0'){ ?> disabled <?php   } ?> onclick="addtocart(<?php echo $row["prod_id"]?>)" />

最新更新