Last active
April 1, 2020 20:14
-
-
Save goliver79/3bc8dba5fbde33213e072bdd642f587b to your computer and use it in GitHub Desktop.
Woocommerce hide other shipments if free shipment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ( ! defined( 'WPINC' ) ) { | |
die; | |
} | |
if ( !class_exists( 'HideShipmentsIfFree' ) ) { | |
class HideShipmentsIfFree { | |
function activate() { | |
add_action( 'woocommerce_package_rates', array( $this, 'hide_shipments_if_free' ), 100 ); | |
} | |
function hide_shipments_if_free( $rates ) { | |
$free = array(); | |
foreach ( $rates as $rate_id => $rate ) { | |
if ( 'free_shipping' === $rate->method_id ) { | |
$free[ $rate_id ] = $rate; | |
break; | |
} | |
} | |
return ! empty( $free ) ? $free : $rates; | |
} | |
} | |
$hide_shipments = new HideShipmentsIfFree(); | |
$hide_shipments->activate(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment