Pages

Monday, March 18, 2013

Hide other shipping methods when FREE SHIPPING is available - woocommerce



// Hide standard shipping option when free shipping is available
add_filter( 'woocommerce_available_shipping_methods', 'hide_standard_shipping_when_free_is_available' , 10, 1 );

/**
* Hide Standard Shipping option when free shipping is available
*
* @param array $available_methods
*/
function hide_standard_shipping_when_free_is_available( $available_methods ) {

if( isset( $available_methods['free_shipping'] ) AND isset( $available_methods['flat_rate'] ) ) {

// remove standard shipping option
if( isset( $available_methods['free_shipping'] ) ) {
$freeShipping = $available_methods['free_shipping'];
unset( $available_methods );

$available_methods['free_shipping'] = $freeShipping;
}
return $available_methods;
}

return $available_methods;
}

No comments: