I want to restrict the customer to place order of less than INR 400 for 2 states. So far i have tried this
add_action( 'woocommerce_check_cart_items', 'set_min_total' );
function set_min_total() {
// Only run in the Cart or Checkout pages
if( is_cart() || is_checkout() ) {
global $woocommerce;
// Set minimum cart total
$minimum_cart_total = 400;
?>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('#billing_state').on('change',function(){
var optionText = jQuery("#billing_state option:selected").val();
});
});
<?php $selected_state = '<script type="text/javascript">optionText</script>'?>
</script>;
<?php
$allowed_state = 'UP';
if($allowed_state != $selected_state) {
$total = WC()->cart->subtotal;
if( $total <= $minimum_cart_total ) {
// Display our error message
wc_add_notice( sprintf( '<strong>A Minimum of %s %s is required before checking out.</strong>'
.'<br />Current cart's total: %s %s',
$minimum_cart_total,
get_option( 'woocommerce_currency'),
$total,
get_option( 'woocommerce_currency') ),
'error' );
}
}
}
}
but it didn’t worked, please advice where am i doing wrong.
2
Answers
Please check with above code , here amount is 100 you can use as you need
Add the follows codes snippet to achieve the above task –
Codes goes to your active theme’s functions.php.