當未達到 $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>
uj5u.com熱心網友回復:
<input type="button" value="Add to Cart" <?php if ($prod_qty == '0'){ ?> disabled <?php } ?> onclick="addtocart(<?php echo $row["prod_id"]?>)" />
uj5u.com熱心網友回復:
你真的應該為你的專案提供更多資訊。我唯一能想到的是,你嘗試使用 document.getElementById("checkout-button button alt wc-forward").setAttribute("disabled","disabled");
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/410095.html
標籤:
