add_action( 'woocommerce_check_cart_items', 'cw_min_num_products' );
// Only run in the Cart or Checkout pages
function cw_min_num_products() {
if( is_cart() || is_checkout() ) {
global $woocommerce;
// Set the minimum order amount, shipping zone & shipping method before checking out
$minimum_nl = 75;
$minimum_be = 423.50;
$minimum_de = 605;
$belgie = array('BE');
$duitsland = array('DE');
$chosen_shipping = WC()->session->get( 'chosen_shipping_methods' )[0];
$chosen_shipping = explode(':', $chosen_shipping);
// Defining var total amount
$cart_tot_order = WC()->cart->subtotal;
// Compare values and add an error in Cart's total amount
// happens to be less than the minimum required before checking out.
// Will display a message along the lines
if( $cart_tot_order < $minimum_be && in_array( WC()->customer->get_shipping_country(), $belgie ) ) {
// Display error message
wc_add_notice( sprintf( 'Om te kunnen bestellen moet uw bestelling een minimale waarde hebben van € 350 ex. BTW. (exlcusief verzendkosten)',
$minimum_be,
$cart_tot_order ),
'error' );
} elseif( $cart_tot_order < $minimum_de && in_array( WC()->customer->get_shipping_country(), $duitsland ) ) {
// Display error message
wc_add_notice( sprintf( 'Om te kunnen bestellen moet uw bestelling een minimale waarde hebben van € 500 ex. BTW. (exlcusief verzendkosten)',
$minimum_de,
$cart_tot_order ),
'error' );
}
}
}
#bestelling #cart #functions #order #woocommerce