• Hello,

    your plugin works great, but I was wondering how to set it up to be “free” for orders eligible for free shipping? Obviously it can be hidden, so it’s not charged, but then parcelshop cannot be selected and the whole point of this plugin is lost so.. any ideas?

    Thanks.

Viewing 1 replies (of 1 total)
  • I solved it by pasting this code into child theme’s functions.php file. It sets the shipping fees for all shipping methods to 0.

    function filter_woocommerce_package_rates( $rates, $package ) {
        // Cart total amount (integer)
        $cart_total = WC()->cart->cart_contents_total;
    
        // Greater than or equal to
        if ( $cart_total >= 59.99 ) {
            foreach ( $rates as $rate_key => $rate ) {
                // For "free shipping" method (enabled), remove it
                if ( $rate->method_id == 'free_shipping' ) {
                    unset( $rates[$rate_key] );
                // For other shipping methods
                } else {
                    // Append rate label titles (free)
                    $rates[$rate_key]->label .= ' ' . __( '(free)', 'woocommerce' );
    
                    // Set rate cost
                    $rates[$rate_key]->cost = 0;
    
                    // Set taxes rate cost (if enabled)
                    $taxes = array();
    
                    foreach ( $rates[$rate_key]->taxes as $key => $tax ) {
                        if ( $rates[$rate_key]->taxes[$key] > 0 ) {
                            $taxes[$key] = 0;
                        }
                    }
    
                    $rates[$rate_key]->taxes = $taxes;
                }
            }
        }
    
        return $rates;
    }
    add_filter( 'woocommerce_package_rates','filter_woocommerce_package_rates', 10, 2 );
Viewing 1 replies (of 1 total)
  • The topic ‘Freeshipping’ is closed to new replies.