Created
February 15, 2022 18:32
-
-
Save wpflames/6d7f4f8ba8070c0d27974ca81199a94e to your computer and use it in GitHub Desktop.
Disable Specific Shipping Method based on Category
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 | |
| // ========================================================================= | |
| // UNSET SPECIFIC SHIPPING METHOD BASED ON CATEGORY IN THE CART | |
| // ========================================================================= | |
| function unset_shipping_based_on_category( $rates) { | |
| $gift_in_cart = false; | |
| // Gift | |
| foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { | |
| if ( has_term( 'nem-virag', 'product_cat', $cart_item['product_id'] ) ) { | |
| $gift_in_cart = true; | |
| break; | |
| } | |
| } | |
| if($gift_in_cart) { | |
| unset( $rates['flat_rate:20'] ); | |
| } | |
| return $rates; | |
| } | |
| add_filter( 'woocommerce_package_rates', 'unset_shipping_based_on_category'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment