Last active
December 4, 2023 12:11
-
-
Save hamidrezayazdani/dfe72a75d70b00ee4c990bcd544c3eb4 to your computer and use it in GitHub Desktop.
Hide specific shipping method if a shipping class is showing
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 | |
function ywp_hide_tipax_for_specific_product( $rates, $package ) { | |
if ( is_admin() && ! wp_doing_ajax() ) { | |
return $rates; | |
} | |
$excluded_class = 23087; // find it like the attached image ( finding-class-shipping-id.jpg ) | |
$tipax_method_id = 'flat_rate:28'; // find it like the attached image ( finding-shipping-method-key.jpg ) | |
foreach ( $package['contents'] as $item ) { | |
if ( $item['data']->get_shipping_class_id() == $excluded_class ) { | |
unset( $rates[ $tipax_method_id ] ); | |
break; | |
} | |
} | |
return $rates; | |
} | |
add_filter( 'woocommerce_package_rates', 'ywp_hide_tipax_for_specific_product', 10, 2 ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment