Last active
February 21, 2024 10:17
-
-
Save kreamweb/f93d783b72e745ff013d76d447fcdff8 to your computer and use it in GitHub Desktop.
woocommerce-shipping-filter
This file contains 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 | |
/* this function remove free shipping if the discount of dynamic is applied in the cart */ | |
if( class_exists('YITH_WC_Dynamic_Discounts') ){ | |
add_filter( 'woocommerce_shipping_packages', 'show_packages' ); | |
function show_packages($packages){ | |
$label = YITH_WC_Dynamic_Discounts()->label_coupon; | |
$newpack = $packages; | |
foreach ( $packages as $key_package => $package ) { | |
if( isset( $package['applied_coupons'] ) && in_array( $label, $package['applied_coupons'] ) ){ | |
if ( sizeof( $package['rates'] ) > 0 ) { | |
foreach ( $package['rates'] as $key_rate => $rate ) { | |
if( $rate->method_id == 'free_shipping' ){ | |
unset($newpack[$key_package]['rates'][$key_rate]); | |
} | |
} | |
} | |
} | |
} | |
return $newpack; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment