Home Forums WoodMart support forum Shipping price display

Shipping price display

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #621519

    zan
    Participant

    Hello.
    I would like to ask how can I hide flat rate shipping option on the checkout page if free shipping is available? I tried code from woocommerce (https://developer.woocommerce.com/docs/free-shipping-customizations/) docs but it doesn’t work with this theme.

    #621666

    Hello,

    Please try to add the following snippet to your child theme’s functions.php file:

    add_filter('woocommerce_package_rates', 'hide_flat_rate_when_free_shipping_available', 10, 2);
    
    function hide_flat_rate_when_free_shipping_available($rates, $package) {
        // Check if free shipping is available
        if (isset($rates['free_shipping'])) {
            // Remove flat rate shipping
            unset($rates['flat_rate']);
        }
        return $rates;
    }

    Best Regards.

    #621866

    zan
    Participant

    The code doesn’t work.
    Also I found another problem.
    If I add 3 products the price is 50,7€ and in this case the option for free shipping is displayed.
    If I add 6 products in total the option for free shipping is not even displayed any more. Only flat rate shipping is displayed in that case. I think there is some kind of additional error that for orders over 100€ free shipping is not available any more and that is not ok. For all orders over 50€ only free shipping option must be displayed.
    Can you please check this.

    #621873

    zan
    Participant

    I found a solution for orders over 100€ I had to change the calculation setting in free shipping bar from custom to based of woocommerce.

    But the first part of the problem is still there. The code you have sent to me for removing flat rage when free shipping is available doesn’t work.

    #621972

    Hello,

    Please delete the old code and use this below code:

    /**
     * Hide shipping rates when free shipping is available, but keep "Local pickup" 
     * Updated to support WooCommerce 2.6 Shipping Zones
     */
    
    function hide_shipping_when_free_is_available( $rates, $package ) {
    	$new_rates = array();
    	foreach ( $rates as $rate_id => $rate ) {
    		// Only modify rates if free_shipping is present.
    		if ( 'free_shipping' === $rate->method_id ) {
    			$new_rates[ $rate_id ] = $rate;
    			break;
    		}
    	}
    
    	if ( ! empty( $new_rates ) ) {
    		//Save local pickup if it's present.
    		foreach ( $rates as $rate_id => $rate ) {
    			if ('local_pickup' === $rate->method_id ) {
    				$new_rates[ $rate_id ] = $rate;
    				break;
    			}
    		}
    		return $new_rates;
    	}
    
    	return $rates;
    }
    
    add_filter( 'woocommerce_package_rates', 'hide_shipping_when_free_is_available', 10, 2 );

    Best Regards.

    #622867

    zan
    Participant

    This code now works. Thank you.

    I have another problem.

    Attachments:
    You must be logged in to view attached files.
    #623061

    zan
    Participant

    Can you please help me solve the variation style problem as well?

    #623323

    Hello,

    May be there is an issue with the 3rd party plugins. Please deactivate all the 3rd party plugins and activate only theme-required plugins on the site and then check the issue. I am sure your issue will be solved. Then Activate the 3rd party plugins one by one and check which plugin is creating the issue for you.

    Otherwise, if the issue still exists then keep the 3rd party plugins deactivated and let me know so I will check and give you a possible solution.

    Best Regards.

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