• Hello, I have question, how to hook your shipping method.

    I have this function to hide all other shipping methods, when Free Shiping is active (order amount is more then X);
    – I am trying to hide all methods instead of yours. In case, if I use classic woo local pickup (local_pickup), it works fine, but I need to hook your method to show your “WC Pickup Store”.

    /**
     * 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 );

    It’s snippet directly from woo: https://docs.woocommerce.com/document/hide-other-shipping-methods-when-free-shipping-is-available/

    Thank you so much for help ??

    • This topic was modified 4 years, 1 month ago by wpsensej.
    • This topic was modified 4 years, 1 month ago by wpsensej.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Keylor Mendoza

    (@keylorcr)

    Hello @wpsensej

    The code works fine as you expected, you just need to change the slug local_pickup to wc_pickup_store. You can get this last one if you inspect your shipping options from the Checkout.

    Hope it helps

    Regards!

    Thread Starter wpsensej

    (@wpsensej)

    Thank you, great! Yes, I should only want to know how to hook your shipping method in this code.

    We have another problem with some bugs. If customers switch from one payment method to another, then “Store selection” will disappear.

    I already wrote you an email to give us payment support for this problem, cause we really need to improve and get working properly on this “issue”. It’s probably in conflict with some plugin or .js, but we don’t know which one, I can’t see anything in the console.

    Thank you.

    Plugin Author Keylor Mendoza

    (@keylorcr)

    Hello @wpsensej

    I’ve already written you back even with some screenshots. Can you please check for this email and confirm if you receive it. If not, please write me again for trying to help you much better.

    Keep in touch

    Regards

    Thread Starter wpsensej

    (@wpsensej)

    Hello, I didn’t received your mail :/

    Going to write you again, please send me your mail again.
    Or maybe if your’re able to this little freelance work, I will be happy too ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Hide other methods – Free shipping’ is closed to new replies.