Support » Plugin: Table Rate for WooCommerce by Flexible Shipping » Filter “woocommerce_cart_contents_weight” not working after the last update

  • Resolved robertorlinski

    (@robertorlinski)


    Hi,

    after last plugin update (4.0 and next), filter “woocommerce_cart_contents_weight” is not working. When I try to downgrade plugin to the 3.16.5 version, everything works fine.

    Is it something wrong with the Flexible Shipping plugin or I have to use something implemented in the plugin itself to add specific weight to every WooCommerce order?

    Thank you in advance.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Contributor grola

    (@grola)

    Hi,

    can you paste sample code here which doesn’t work with 4.0 and works with older plugin versions?

    Best regards,
    Grzegorz

    Thread Starter robertorlinski

    (@robertorlinski)

    Sure!

    Here is the code:

    
    add_filter('woocommerce_cart_contents_weight', 'add_package_weight_to_cart_contents_weight');
    function add_package_weight_to_cart_contents_weight( $weight ) {        
      $weight = $weight + 250;  
      return $weight; 
    }
    
    Plugin Contributor grola

    (@grola)

    From version 4.0, the weight is calculated as the sum of all products. We don’t use the woocommerce get_cart_contents_weight function.

    Thread Starter robertorlinski

    (@robertorlinski)

    Hmm, understandable.

    In this case, which way would be ok to achieve similar results which will work in this plugin version and lasts in the next ones?

    Plugin Contributor grola

    (@grola)

    Why do you need this?

    You can change the weight of a single product in the filters or change the ranges in the shipping method rules.

    Thread Starter robertorlinski

    (@robertorlinski)

    I have to add package weight to every order which is fixed, so I can’t change single product weight since it would multiple.

    Changing ranges would be possible but when I have about 120 different shipping locations, changing everything will be tedious (now and if it someday comes to package weight change).

    Thats why filter I have put here, was so useful.

    Plugin Contributor grola

    (@grola)

    Thanks for the clarification. We will consider a solution to this problem. We’ll probably add our own filter. We’ll let you know when it’s available.

    Thread Starter robertorlinski

    (@robertorlinski)

    Thank you so much. So, I will wait for any information about work progress, hope implementation won’t last long.

    Plugin Contributor grola

    (@grola)

    Hi,

    @robertorlinski we just added flexible-shipping/condition/contents_weight filter. You can use it like this:

    
    add_filter('flexible-shipping/condition/contents_weight', 'add_package_weight_to_cart_contents_weight');
    function add_package_weight_to_cart_contents_weight( $weight ) {        
      $weight = $weight + 250;  
      return $weight; 
    }
    
    Thread Starter robertorlinski

    (@robertorlinski)

    Awesome! Thank you so much 🙂

Viewing 10 replies - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.