0

The minimum order amount has to be 1500. I use this code to show the message in the cart, and to disable 'proceed to checkout' action, if the amount is less then 1500.

add_action( 'woocommerce_before_cart', 'truemisha_minimum_order_amount' );
 
function truemisha_minimum_order_amount(){
 
  $minimum_amount = 1500;
 
  if ( WC()->cart->subtotal < $minimum_amount ) {
 
    wc_print_notice(
      sprintf(
        'The minimum order amount is %s, your order amount is %s.' ,
        wc_price( $minimum_amount ),
        wc_price( WC()->cart->subtotal )
      ),
      'notice'
    );
  }
 
}

add_action( 'woocommerce_before_checkout_form', 'truemisha_minimum_order_amount' );
add_action( 'woocommerce_checkout_process', 'truemisha_no_checkout_min_order_amount' );
 
function truemisha_no_checkout_min_order_amount() {
 
  $minimum_amount = 1500;
 
  if ( WC()->cart->subtotal < $minimum_amount ) {
 
    wc_add_notice( 
      sprintf( 
        'The minimum order amount is %s, your order amount is %s.',
        wc_price( $minimum_amount ),
        wc_price( WC()->cart->subtotal )
      ),
      'error'
    );
 
  }
 
}

function disable_checkout_button() {
 
// Set this variable to specify a minimum order value
$minimum = 1500;
$total = WC()->cart->cart_contents_total;
if( $total < $minimum ){
remove_action( 'woocommerce_proceed_to_checkout', 'woocommerce_button_proceed_to_checkout', 20 );
echo ' <form><input type="button" style="display: inline-block;" class="checkout-button button alt wc-forward " value="Back to the product" onClick="history.back()">
</form>

 <a style="pointer-events: none !important; background: #dfe1f0; border-color: #dfe1f0; color: rgba(51,51,51,.5); cursor: no-drop; display: inline-block;" href="#" class="checkout-button button alt wc-forward">Proceed to checkout</a><p style="font-weight: bold;">The minimum order amount is<span style="color:red;">'.$minimum.'</span> ₽. </p>';
}
}
 
add_action( 'woocommerce_proceed_to_checkout', 'disable_checkout_button', 1 );

I need the same in the product page, for add to cart button - NOT HIDE OR DELETE IT, exactly disable, if the order amount is<1500. What's the right hook for it?

libertarian
  • 345
  • 1
  • 15
  • 1
    I don't get it - So if there is less than 1500 in the cart, you can't add anything to the cart? That sounds like the button will always be disabled, since you can't add anything to the cart before you have stuff in your cart? – Stender Feb 17 '22 at 12:50
  • You are right.... I thought about not disabling all form, only button, to use quantity input for choosing the needed amount. Is it possible? Or what's the better idea? – libertarian Feb 17 '22 at 12:58
  • In this case I would use front-edn and not back-end, to check the sum of the cart, and to enable/disable the button – Shir Gans Feb 17 '22 at 13:23
  • I'm trying that way https://stackoverflow.com/questions/71161371/how-to-make-add-to-cart-button-disabled-when-the-amount-is-less-then-minimum-and, but something is wrong in my jquery, what am I missing? – libertarian Feb 17 '22 at 16:03
  • Update your question/issue with what you have tried. – Bazdin Feb 17 '22 at 19:02
  • As well, it makes it seem like I have to order 1500 of the samething? – Bazdin Feb 17 '22 at 19:03

1 Answers1

0
function disable_checkout_button_no_shipping() { 
    $minimum = 100;
    if (WC()->cart->total < $minimum ) {
       remove_action('woocommerce_proceed_to_checkout',
              'woocommerce_button_proceed_to_checkout', 20 );
        echo '<a href="#" class="checkout-button button alt wc-forward">
         Proceed to checkout 1</a>';
    }  
}

add_action('woocommerce_proceed_to_checkout','disable_checkout_button_no_shipping', 1);
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 07 '22 at 19:02