Skip to content

Instantly share code, notes, and snippets.

@kreamweb
Last active February 21, 2024 10:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kreamweb/f93d783b72e745ff013d76d447fcdff8 to your computer and use it in GitHub Desktop.
Save kreamweb/f93d783b72e745ff013d76d447fcdff8 to your computer and use it in GitHub Desktop.
woocommerce-shipping-filter
<?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