• Hello!
    I want to set the minimum cart amount to order. I have 2 currencies and with this basic currency all works wine but not with custom.
    Here is the code I use:

    add_action( 'woocommerce_checkout_process', 'grib_wc_minimum_order_amount' );
    add_action( 'woocommerce_before_cart', 'grib_wc_minimum_order_amount' );
      
    function grib_wc_minimum_order_amount() {
    	
    	$currency = get_woocommerce_currency();
    
    		if ($currency == 'GBP'){
    			$minimum = 20;
    		} else{
    			$minimum = 800;
    		}
     
        if ( WC()->cart->subtotal < $minimum ) {
     
            if( is_cart() ) {
     
                wc_print_notice( 
                    sprintf( 'Минимальная сумма заказа <b>%s</b>. Сумма вашего заказа <b>%s</b>. Добавьте больше ?? <a href="/magazin/">Перейти в каталог</a>' , wc_price( $minimum ), wc_price( WC()->cart->subtotal ) ), 'error'
                );
     
            } else {
     
                wc_add_notice( 
                    sprintf( 'Минимальная сумма заказа <b>%s</b>. Сумма вашего заказа <b>%s</b>. Добавьте больше ?? <a href="/magazin/">Перейти в каталог</a>' , wc_price( $minimum ), wc_price( WC()->cart->subtotal ) ), 'error'
                );
     
            }
        }
     
    }

    I think that the second and else currencies doesn’t use the get_woocommerce_currency(); function. So what should I do to make this snippet work with the Multi Currency for WooCommerce?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi.

    You need get current currency by this code:

    $data = WOOMULTI_CURRENCY_F_Data::get_ins();
    $currency = $data->get_current_currency();
    
    Thread Starter Alexander

    (@donatory)

    Thanks for the code but no effect.
    Notice shows only for basic currency.

    Here is the code I use:

    add_action( 'woocommerce_checkout_process', 'grib_wc_minimum_order_amount' );
    add_action( 'woocommerce_before_cart', 'grib_wc_minimum_order_amount' );
      
    function grib_wc_minimum_order_amount() {
    	
    	$data = WOOMULTI_CURRENCY_F_Data::get_ins();
    	$currency = $data->get_current_currency();
    
    		if ($currency == 'GBP'){
    			$minimum = 20;
    		} else{
    			$minimum = 800;
    		}
     
        if ( WC()->cart->subtotal < $minimum ) {
     
            if( is_cart() ) {
     
                wc_print_notice( 
                    sprintf( 'Минимальная сумма заказа <b>%s</b>. Сумма вашего заказа <b>%s</b>. Добавьте больше ?? <a href="/magazin/">Перейти в каталог</a>' , wc_price( $minimum ), wc_price( WC()->cart->subtotal ) ), 'error'
                );
     
            } else {
     
                wc_add_notice( 
                    sprintf( 'Минимальная сумма заказа <b>%s</b>. Сумма вашего заказа <b>%s</b>. Добавьте больше ?? <a href="/magazin/">Перейти в каталог</a>' , wc_price( $minimum ), wc_price( WC()->cart->subtotal ) ), 'error'
                );
     
            }
        }
     
    }

    I tested, it works, no bug in your code. https://prnt.sc/tyr4yr

    • This reply was modified 4 years, 3 months ago by thanhtd.
    Thread Starter Alexander

    (@donatory)

    Ok, I’ll test again.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Minimal order amount with multi currencies’ is closed to new replies.