Solved it. Just remeber to add the same shipping class to all variations too.
add_filter( 'woocommerce_package_rates', 'custom_shipping_rates', 100, 2 );
function custom_shipping_rates( $rates, $package ) {
$shipping_class = 506; // HERE set the shipping class ID
$found = false;
$productsincart = count($package['contents']);
foreach( $package['contents'] as $cart_item ) {
if ($productsincart == 1 && $cart_item['data'];->get_shipping_class_id() == $shipping_class){
$found = true;
}
}
if ( $found ) {
return false; // If not found we exit
}else {
return $rates;
}
}
Related Posts:
- Show only geolocated user country into Woocommerce checkout country fields
- Reverse engineering of WooCommerce Storefront filters
- How to modify “[Product] has been added to your cart” in WooCommerce?
- WordPress codex: apply_filters – clarification on creating a new hook on the fly. How do we use it?
- Is there a Woocommerce hook that fires when applying a coupon but before checking if it’s valid?
- Filter on a custom product attribute in WooCommerce using meta_query or tax_query [closed]
- Rewriting Woocommerce Product Filters To URL Segments
- What is the action hook for an order that fails on frontend checkout in WooCommerce?
- woocommerce_get_price filter hook not working for product variation price
- Accessing parameters when adding filter
- Using a filter with multiple parameters and $this
- Remove add to cart icon/view product button woocommerce
- Separeting product from post in search result
- Woocommerce get billing state manually
- Redirect customer to login page (with other signup plugin) if user not logged in when proceeding to checkout
- Woocommerce: Complex query in pre_get_posts [closed]
- Using a filter to change a path
- Pre filter woocommerce products to remove a certain category of products
- How to apply these filters
- How to add order status class to the body tag?
- Redirect no product url’s to static url
- What Hook/Action is performed when a field in checkout form is changed in WooCommerce
- How can I remove a WooCommerce Product Tab’s sub section in wp-admin?
- How do I create a filter to hide the One Click Accessibility plugin button in WordPress?
- manage_shop_order_posts_custom_column() hook is Not working In Functions.php file in my WordPress active theme
- Display custom product option in admin order details
- How to create a WooCommerce Product filter based on PHP foreach
- Woocommerce : Add name filed of checkout page to buyers wordpress display name
- Two Filter Issue [closed]
- apply_filter and add_filter conflict
- Running JavaScript after using WooCommerce Filter Plugin
- Redirecting orders by company field
- Combine one action and one filter
- I’m getting error Ultimate WooCommerce Filters
- How to add woocommerce product price filter widget to other page
- How can i add product Accessories from front-end using custom php form?
- How to change lost password email text using custom plugin wordpress?
- Overriding Plugin function in your child theme
- Update / refresh mini cart, after custom AJAX add_to_cart event
- Filter orders in Admin area based on logged in user
- WooCommerce Tax Filter Not Working
- Add suffix to price html does not work
- woocommerce price filter not working when change currency
- With what hook do I remove WooCommerce existing Product Data Tab form fields?
- AffiliateWP not calculating multiple quantities when using affwp_calc_referral_amount filter
- Add second price option based on payment method at cart item price
- How to get the attributes based on dependency in woocommerce?
- Reposition variation stock message
- Add custom ID to WooCommerce product tab
- Get the product list of a given Category ID
- Correct function to get the user’s latest Woocommerce Subscription?
- Move payment options at checkout in WooCommerce [closed]
- WooCommerce – Hook after Loading Variation in Admin Edit page?
- WooCommerce conditional meta query
- Username field is not shown in Woocommerce’s registration contact form
- Woocommerce Membership Expiry Date
- Woocommerce SKU on ALL products page [closed]
- Redirect user to cart page when add to cart button is clicked
- Woo API REST : product variation price is read-only?
- Problems with varibel price [closed]
- Add to cart php not working [closed]
- Custom Admin Email Subject for Woocommerce (3.8.0) Orders
- Woocommerce custom endpoints
- How to override Woocommerce functionality in Reports section?
- how can use woocommerce add to cart popup?
- Adding a Clone link to product attributes – post_row_actions() filter, or how to override a Class question
- Remove link from product attributes in tab “additional information” [closed]
- Merging updated dev site with live site while keeping orders correct
- Get decimal from product price with Mysql
- Woocommerce – Shop page repeat the products with filters
- Allow only 1 quantity of particular product in cart WooCommerce
- Hide price and add to cart button on product page only
- Order woocommerce products alphabetically by second word in title?
- Apply a custom WooCommerce order status based on user role
- Woocommerce product name [closed]
- How to Remove Active css from woocommerce variation?
- Password protected selling / selling one product at the time
- SOLVED – add_action() for $product->get_date_created
- Woocommerce – how to round up all prices to end in .99
- Display WooCommerce product attribute on shop page
- How to get product category ID based on post?
- Remove Stripe Woocommerce Credit Card Icons (and replace with image)
- How to add external product url to woocommerce from a metadata by function.php
- Unable to call woocommerce hook in my custom php file
- Custom account page that accepts a query parameter
- Custom WooCommerce template for product
- Checkout fr Woocommerce – load default WooCommerce checkout template on the fly
- Loop Through Current Woocommerce Product Categories Sub Categories
- Two types of product categories on shop page
- HTTP Error when uploading pictures and problem with the size of images
- add_rewrite_rule() returns 404 page
- Woocommerce Setup not completing
- WooCommerce – Adding Product Attributes to CSV Export
- Unable to enocde the result of wc_get_products
- Woocommerce Add to Cart function
- WooCommerce – doesn’t show product when using woocommerce.php [closed]
- WordPress error
- How to add product thumbnail on orders list on backend?
- Hide price, “add to cart” button and show message “Please log in to shop” [closed]
- Custom plugin development with paypal subscription method