Applied coupons disable Free shipping conditionally in Woocommerce

The below code will enable “Free shipping” for applied coupons only if cart subtotal reaches a minimal amount (discounted including taxes): add_filter( ‘woocommerce_package_rates’, ‘coupons_removes_free_shipping’, 10, 2 ); function coupons_removes_free_shipping( $rates, $package ){ if ( is_admin() && ! defined( ‘DOING_AJAX’ ) ) return $rates; $min_subtotal = 250; // Minimal subtotal allowing free shipping // Get needed … Read more

Get orders shipping items details in WooCommerce 3

If you want to get the Order Items Shipping data, you need first to get them in a foreach loop (for ‘shipping’ item type) and to use WC_Order_Item_Shipping methods to access data $order_id = 528; // For example // An instance of $order = wc_get_order($order_id); // Iterating through order shipping items foreach( $order->get_items( ‘shipping’ ) … Read more

WooCommerce – Hide other shipping methods when FREE SHIPPING is available

There is this recent code snippet for WooCommerce 2.6+. that you can Use: add_filter( ‘woocommerce_package_rates’, ‘hide_other_shipping_when_free_is_available’, 100, 2 ); function hide_other_shipping_when_free_is_available( $rates, $package ) { $free = array(); foreach ( $rates as $rate_id => $rate ) { if ( ‘free_shipping’ === $rate->method_id ) { $free[ $rate_id ] = $rate; break; } } return ! empty( … Read more

Show hide payment methods based on selected shipping method in Woocommerce

The following code example will enable / disable payment gateways based on chosen shipping method. In this example, we have 3 shipping methods and 3 payment gateways. Each selected shipping method will enable only one different payment gateway. add_filter( ‘woocommerce_available_payment_gateways’, ‘payment_gateways_based_on_chosen_shipping_method’ ); function payment_gateways_based_on_chosen_shipping_method( $available_gateways ) { // Not in backend (admin) and Not in … Read more

Hide shipping methods for specific shipping class in WooCommerce

Update 2019: You should try instead this shorter, compact and effective way: add_filter( ‘woocommerce_package_rates’, ‘hide_shipping_method_based_on_shipping_class’, 10, 2 ); function hide_shipping_method_based_on_shipping_class( $rates, $package ) { if ( is_admin() && ! defined( ‘DOING_AJAX’ ) ) return; // HERE define your shipping class to find $class = 92; // HERE define the shipping method to hide $method_key_id = … Read more