Skip to content

Instantly share code, notes, and snippets.

@hamidrezayazdani
Last active December 4, 2023 12:11
Show Gist options
  • Save hamidrezayazdani/dfe72a75d70b00ee4c990bcd544c3eb4 to your computer and use it in GitHub Desktop.
Save hamidrezayazdani/dfe72a75d70b00ee4c990bcd544c3eb4 to your computer and use it in GitHub Desktop.
Hide specific shipping method if a shipping class is showing
<?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