Great question — answering as the UphillTech team:
This doesn't require any code normally… You should set your shipping method as follow (so first remove your code and save) : 1) So you will keep 120 as global cost in your shipping method. 2) Then for each related desired shipping class you will add in the corresponding field: [qty]*70 for shipping-class-1 [qty]*50 for shipping-class-2 Calculation type: Per class: Charge shipping for each shipping class individually This will work and will add to the cost an amount by chipping class based on cart item quantity. For a custom shipping method based on your code, you should use the following to handle item quantity: add_filter( 'woocommerce_package_rates',...
Full answer by LoicTheAztec: https://stackoverflow.stackexchange.com/a/60751624 (CC BY-SA 4.0).
Need it done for your business? UphillTech.