0

I'm having difficulty with the shipping classes in WooCommerce. It's a webshop containing products for mailbox and packages.

However, if the cart contains 3 or more "mailbox" products, then the shipping class should change to "package".

I've tried changing the code from this question: Change shipping class based on cart items shipping class count in Woocommerce , but I couldn't figure it out.

Can someone help me with this?

  • What did you change? What is the problem? – Aaron Aug 31 '20 at 22:18
  • I tried to change this line `$cart_item['data']->set_shipping_class_id('0');` to a different ID, which didn't work. I tried to add a shipping class `$package_shipping_class = 'package';` and place it as `$cart_item['data']->get_shipping_class() ==$package_shipping_class );` on the last line (so instead of `$cart_item['data']->set_shipping_class_id('0');` Then when I go to my cart and I add 3 products it just says the label "Shipping costs" with actually adding shipping costs. – Shanice Sep 01 '20 at 10:01
  • I found a different solution. Thank you :) – Shanice Sep 02 '20 at 14:19

1 Answers1

-1

The problem could be that you change the slug naming in the code.
Just implemented this and works fine!

// HERE define your shipping class SLUG
$mailbox_shipping_class = 'your-mailbox-shipping-class-slug';
Yunnosch
  • 26,130
  • 9
  • 42
  • 54
  • Please avoid asking questions (even rhetoric ones) in answers, it risk being flagged as "not an answer". – Yunnosch Dec 01 '20 at 08:24