• Resolved kh4n605

    (@kh4n605)


    The flexible shipping plugin calculates total weight by adding per product weight. Here I want to calculate the total weight for example – (weight1 + weight2)/2 and assign this weight to the Flexible shipping Plugin so that the plugin applies conditions for this weight.

    I am almost near to the solution. But I don’t know how to assign custom total weight in the plugin.

    add_filter('woocommerce_cart_contents_weight', 'custom_cart_contents_weight', 10, 1);
    function custom_cart_contents_weight($weight)
    {
        global $total_weight;
        $weight = $total_weight;
        return $weight;
    }

    With this code, I can change the total weight for WooCommerce but your plugin doesn’t apply a condition for my calculated weight. How to solve it?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Support kozyraola

    (@kozyraola)

    Hi @kh4n605,

    Can you elaborate further why you need custom total weight?

    The plugin is calculating total weight based on the products in the cart.
    However, you need to create a shipping method based on weight first.

    Please see here

    Best regards,
    Ola

    Thread Starter kh4n605

    (@kh4n605)

    The plugin calculates total weight by summing up all the product’s weight. But I need to figure the total weight by this calculation: heaviest product’s weight + (rest of the products weight) * 0.35 = total weight.

    I have made this calculation and got the value successfully. I want the plugin to make conditions with this weight, not the total weight.

    I can change WooCommerce total weight by this filter hook –

    add_filter('woocommerce_cart_contents_weight', 'custom_cart_contents_weight', 10, 1);
    function custom_cart_contents_weight($weight)
    {
        global $total_weight;
        $weight = $total_weight;
        return $weight;
    }

    How to assign this weight to the total weight your plugin applies the condition for?

    Plugin Author grola

    (@grola)

    Thread Starter kh4n605

    (@kh4n605)

    Can you please give me an example of how to filter your hooks so that it uses my calculated weight? Actually, I am not understanding the hooks you refer to.

    add_filter('flexible-shipping/condition/contents_weight', 'custom_cart_contents_weight', 10, 1);
    function custom_cart_contents_weight($contents_weight)
    {
        global $total_weight;
        $contents_weight = $total_weight;
        return $contents_weight;
    }

    It’s not working.

    • This reply was modified 2 years, 3 months ago by kh4n605.
    Plugin Author grola

    (@grola)

    Hi,

    if in global $total_wight is the correct value, it should work. Please, enable debug mode in shipping method and paste debug messages.

    Kind regards
    Grzegorz

    Thread Starter kh4n605

    (@kh4n605)

    Here is the debug messages.

    Method settings:
     Enabled: yes
     Method Title: Flexible Shipping
     Method Description: 
     Tax status: None
     Costs includes tax: no
     Free Shipping: 
     Free Shipping Label: Free
     'Left to free shipping' notice: no
     Rules Calculation: Sum
     Cart Calculation: Package value
     Visibility (Show only for logged in users): no
     Default: no
     Debug mode: yes
    Integration: none 
    
    Contents value: 145 BDT
    Contents weight: 50 kg 
    
    Rule 1:
       Condition: Weight; min: 25; max: 35; input data: 0; matched: no
    Rule 2:
       Condition: Weight; min: 35.1; max: 60; input data: 0; matched: no 
    
    Used and displayed in the cart/checkout: no
    Plugin Author grola

    (@grola)

    Hi,

    the input weight for conditions is 0. So global $total_weight is 0.

    Where and when is global $total_weight calculated?

    Plugin Support tograczyk

    (@tograczyk)

    As we haven’t got any replies, I’m marking this topic as resolved for now.

    If you have any additional questions, let us know, we’ll be happy to help.

    Best regards,
    Tomek

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Set custom total weight in WooCommerce’ is closed to new replies.