Home Forums WoodMart support forum WooCommerce Error Shipping 100€+

WooCommerce Error Shipping 100€+

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #640012

    batifix
    Participant

    Hello guys,
    I’m at the end of my ideas, maybe I’m missing something and you can help me!
    We have a flat rate shipping fee of €5.95, with no shipping for orders over €75.
    We also have express shipping for €25, which should always be visible and selectable. The flat rate / free shipping should be selected automatically depending on the shopping cart value, and there is also the option to collect at any time. Now everything works so far, except for the fact that he always chooses the shipping flat rate for orders over €100, why? 75-99.99€ free shipping is chosen.

    functions.php

    add_filter( 'woocommerce_package_rates', 'conditionally_hide_shipping_methods', 100, 2 );
    function conditionally_hide_shipping_methods( $rates, $package ) {
        // Hier die IDs der Versandmethoden, die immer angezeigt werden sollen:
        $flat_rates_express = array( 'flat_rate:15', 'local_pickup:9' );
    
        $free = $flat2 = $flat_rate = array();
        $cart_total = WC()->cart->subtotal; // Gesamtbetrag des Warenkorbs
    
        foreach ( $rates as $rate_key => $rate ) {
            // Überprüfen, ob der Warenkorbwert 75 € oder mehr beträgt
            if ( $cart_total >= 75 ) {
                if ( 'free_shipping' === $rate->method_id ) {
                    $free[ $rate_key ] = $rate; // Kostenlose Versandmethode hinzufügen
                }
            } else {
                // Wenn der Warenkorbwert unter 75 € liegt, die Versandpauschale hinzufügen
                if ( 'flat_rate' === $rate->method_id ) {
                    $flat_rate[ $rate_key ] = $rate; // Versandpauschale hinzufügen
                }
            }
    
            // Expressversand immer hinzufügen
            if ( in_array( $rate->id, $flat_rates_express ) ) {
                $flat2[ $rate_key ] = $rate;
            }
        }
    
        // Wenn kostenlose Versandmethoden vorhanden sind, diese zusammen mit dem Expressversand zurückgeben
        if ( ! empty( $free ) ) {
            return array_merge( $free, $flat2 );
        }
    
        // Wenn der Warenkorbwert unter 75 € liegt, die Versandpauschale zurückgeben
        return ! empty( $flat_rate ) ? array_merge( $flat_rate, $flat2 ) : $rates;
    }
    #640129

    batifix
    Participant

    oh my god.. after hours of searching for similar problems, her is the solution!
    It was not the code, in the woocommerce settings there had to be a “.” (point) instead of the “,” (comma).
    Apparently woocommerce has problems here. It works!

    #640193

    Hung Pham
    Keymaster

    Hi batifix,

    Thanks for reaching to us and appreciate your patience.

    Glad to hear your issue has been resolved. Keep us in mind for future questions and concerns, we’re always here to help!

    Regards,

Viewing 3 posts - 1 through 3 (of 3 total)