Last active
June 9, 2022 08:41
-
-
Save FrancoStino/8a7a7c258ba556c9afcf4df183037ff9 to your computer and use it in GitHub Desktop.
Set a minimum order amount for checkout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Set a minimum order amount for checkout | |
*/ | |
add_action( 'woocommerce_before_checkout_form', 'wc_minimum_order_amount' ); | |
add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' ); | |
add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' ); | |
function wc_minimum_order_amount() { | |
// Set this variable to specify a minimum order value | |
$minimum = 15; | |
if ( WC()->cart->total < $minimum ) { | |
/* DISABILITARE IL PULSANTE PROCEDI AL CHECKOUT */ | |
function disable_checkout_button_no_shipping() { | |
echo '<button class="checkout-button" disabled style="cursor: no-drop;">Concludi ordine</a>'; | |
remove_action( 'woocommerce_proceed_to_checkout', 'woocommerce_button_proceed_to_checkout', 20 ); | |
} | |
add_action( 'woocommerce_proceed_to_checkout', 'disable_checkout_button_no_shipping' ); | |
if( is_cart() ) { | |
wc_print_notice( | |
sprintf( 'Il totale del tuo ordine attuale è di %s: devi avere un ordine con un minimo di %s per poter procedere' , | |
wc_price( WC()->cart->total ), | |
wc_price( $minimum ) | |
), 'error' | |
); | |
}else{ | |
wp_redirect( esc_url( WC()->cart->get_cart_url() ) ); | |
exit; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment